#[non_exhaustive]pub enum MultilineListBuilder<EB> {
Unspecified,
String(String),
List(Vec<EB>),
}
Expand description
Configuration item specifiable as a list, or a single multi-line string
If a list is supplied, they are deserialized as builders.
If a single string is supplied, it is split into lines, and #
-comments
and blank lines and whitespace are stripped, and then each line is parsed
as a builder.
(Eventually, the builders will be built.)
For use with sub_builder
and define_list_builder_helper
,
with #[serde(try_from)]
and #[serde(into)]
.
§Example
use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use tor_config::{ConfigBuildError, MultilineListBuilder};
use tor_config::convert_helper_via_multi_line_list_builder;
use tor_config::{define_list_builder_accessors, define_list_builder_helper};
use tor_config::impl_standard_builder;
#[derive(Debug, Clone, Builder, Eq, PartialEq)]
#[builder(build_fn(error = "ConfigBuildError"))]
#[builder(derive(Debug, Serialize, Deserialize))]
#[non_exhaustive]
pub struct LotteryConfig {
/// What numbers should win the lottery? Setting this is lottery fraud.
#[builder(sub_builder, setter(custom))]
#[builder_field_attr(serde(default))]
winners: LotteryNumberList,
}
impl_standard_builder! { LotteryConfig }
/// List of lottery winners
//
// This type alias arranges that we can put `LotteryNumberList` in `LotteryConfig`
// and have derive_builder put a `LotteryNumberListBuilder` in `LotteryConfigBuilder`.
pub type LotteryNumberList = Vec<u16>;
define_list_builder_helper! {
struct LotteryNumberListBuilder {
numbers: [u16],
}
built: LotteryNumberList = numbers;
default = generate_random();
item_build: |number| Ok(*number);
#[serde(try_from="MultilineListBuilder<u16>")]
#[serde(into="MultilineListBuilder<u16>")]
}
convert_helper_via_multi_line_list_builder! {
struct LotteryNumberListBuilder {
numbers: [u16],
}
}
define_list_builder_accessors! {
struct LotteryConfigBuilder {
pub winners: [u16],
}
}
let lc: LotteryConfigBuilder = toml::from_str(r#"winners = [1,2,3]"#).unwrap();
let lc = lc.build().unwrap();
assert_eq!{ lc.winners, [1,2,3] }
let lc = r#"
winners = '''
# Enny tells us this is the ticket they bought:
4
5
6
'''
"#;
let lc: LotteryConfigBuilder = toml::from_str(lc).unwrap();
let lc = lc.build().unwrap();
assert_eq!{ lc.winners, [4,5,6] }
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Unspecified
Config key not present
String(String)
Config key was a string which is to be parsed line-by-line
List(Vec<EB>)
Config key was a list of the individual entry builders
Trait Implementations§
Source§impl<EB: Clone> Clone for MultilineListBuilder<EB>
impl<EB: Clone> Clone for MultilineListBuilder<EB>
Source§fn clone(&self) -> MultilineListBuilder<EB>
fn clone(&self) -> MultilineListBuilder<EB>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<EB: Debug> Debug for MultilineListBuilder<EB>
impl<EB: Debug> Debug for MultilineListBuilder<EB>
Source§impl<EB> Default for MultilineListBuilder<EB>
impl<EB> Default for MultilineListBuilder<EB>
Source§fn default() -> MultilineListBuilder<EB>
fn default() -> MultilineListBuilder<EB>
Source§impl<'de, EB: Deserialize<'de>> Deserialize<'de> for MultilineListBuilder<EB>
impl<'de, EB: Deserialize<'de>> Deserialize<'de> for MultilineListBuilder<EB>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<EB> Serialize for MultilineListBuilder<EB>where
EB: Serialize,
impl<EB> Serialize for MultilineListBuilder<EB>where
EB: Serialize,
Auto Trait Implementations§
impl<EB> Freeze for MultilineListBuilder<EB>
impl<EB> RefUnwindSafe for MultilineListBuilder<EB>where
EB: RefUnwindSafe,
impl<EB> Send for MultilineListBuilder<EB>where
EB: Send,
impl<EB> Sync for MultilineListBuilder<EB>where
EB: Sync,
impl<EB> Unpin for MultilineListBuilder<EB>where
EB: Unpin,
impl<EB> UnwindSafe for MultilineListBuilder<EB>where
EB: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes
Size for each variant:
Unspecified
: 0 bytesString
: 24 bytesList
: 24 bytes