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>
impl<K, V, DeK, DeV, ESep, KvSep> Debug for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
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>,
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
const EXPECTING: BasicTypes
Describes which parameter this deserializer is expecting.
Source§fn describe(&self, description: &mut TypeDescription)
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>
fn deserialize_param( &self, ctx: DeserializeContext<'_>, param: &'static ParamMetadata, ) -> Result<C, ErrorWithOrigin>
Performs deserialization given the context and param metadata. Read more
Auto Trait Implementations§
impl<K, V, DeK, DeV, ESep, KvSep> Freeze for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
impl<K, V, DeK, DeV, ESep, KvSep> RefUnwindSafe for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
impl<K, V, DeK, DeV, ESep, KvSep> Send for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
impl<K, V, DeK, DeV, ESep, KvSep> Sync for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
impl<K, V, DeK, DeV, ESep, KvSep> Unpin for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
impl<K, V, DeK, DeV, ESep, KvSep> UnwindSafe for DelimitedEntries<K, V, DeK, DeV, ESep, KvSep>
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
Mutably borrows from an owned value. Read more