Struct DelimitedEntries

Source
pub struct DelimitedEntries<K, V, DeK = <K as WellKnown>::Deserializer, DeV = <V as WellKnown>::Deserializer, ESep = &'static str, KvSep = &'static str> { /* private fields */ }
Expand description

Delimited variant of Entries that can deserialize a map from a delimited string (with addition to the conventional object deserialization). Can be constructed using Entries::delimited().

DelimitedEntries are characterized by 2 separators: one between entries, and another between key and value.

§Examples

use smart_config::{de, testing, DescribeConfig, DeserializeConfig};

#[derive(DescribeConfig, DeserializeConfig)]
struct TestConfig {
    #[config(with = de::Entries::WELL_KNOWN.delimited(",", "="))]
    map: HashMap<String, i64>,
}

let config = smart_config::config!("map": "call=5,send=-3");
let config: TestConfig = testing::test(config)?;
assert_eq!(
    config.map,
    HashMap::from([("call".into(), 5), ("send".into(), -3)])
);

§Regex separators

Similar configuration that allows for whitespace around separators.

use smart_config::pat::lazy_regex;

#[derive(DescribeConfig, DeserializeConfig)]
struct TestConfig {
    #[config(
        with = de::Entries::WELL_KNOWN.delimited(
            // see `lazy_regex!` docs for the syntax explanation
            lazy_regex!(ref r"\s*,\s*"),
            lazy_regex!(ref r"\s*=\s*"),
        )
    )]
    map: HashMap<String, i64>,
}

let config = smart_config::config!("map": "call = 5, send = -3");
let config: TestConfig = testing::test(config)?;

Trait Implementations§

Source§

impl<K, V, DeK, DeV, ESep, KvSep> Debug for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
where DeK: Debug, DeV: Debug, ESep: Split, KvSep: Split,

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V, DeK, DeV, ESep, KvSep, C> DeserializeParam<C> for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
where DeK: DeserializeParam<K>, DeV: DeserializeParam<V>, ESep: Split, KvSep: Split, C: FromIterator<(K, V)>, Entries<K, V, DeK, DeV>: DeserializeParam<C>,

Source§

const EXPECTING: BasicTypes

Describes which parameter this deserializer is expecting.
Source§

fn describe(&self, description: &mut TypeDescription)

Additional info about the deserialized type, e.g., extended description.
Source§

fn deserialize_param( &self, ctx: DeserializeContext<'_>, param: &'static ParamMetadata, ) -> Result<C, ErrorWithOrigin>

Performs deserialization given the context and param metadata. Read more
Source§

fn serialize_param(&self, param: &C) -> Value

Serializes the provided parameter to the JSON model. Read more

Auto Trait Implementations§

§

impl<K, V, DeK, DeV, ESep, KvSep> Freeze for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
where ESep: Freeze, KvSep: Freeze, DeK: Freeze, DeV: Freeze,

§

impl<K, V, DeK, DeV, ESep, KvSep> RefUnwindSafe for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
where ESep: RefUnwindSafe, KvSep: RefUnwindSafe, DeK: RefUnwindSafe, DeV: RefUnwindSafe,

§

impl<K, V, DeK, DeV, ESep, KvSep> Send for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
where ESep: Send, KvSep: Send, DeK: Send, DeV: Send,

§

impl<K, V, DeK, DeV, ESep, KvSep> Sync for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
where ESep: Sync, KvSep: Sync, DeK: Sync, DeV: Sync,

§

impl<K, V, DeK, DeV, ESep, KvSep> Unpin for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
where ESep: Unpin, KvSep: Unpin, DeK: Unpin, DeV: Unpin,

§

impl<K, V, DeK, DeV, ESep, KvSep> UnwindSafe for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
where ESep: UnwindSafe, KvSep: UnwindSafe, DeK: UnwindSafe, DeV: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more