diff options
Diffstat (limited to 'src/de/mod.rs')
-rw-r--r-- | src/de/mod.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/de/mod.rs b/src/de/mod.rs index 150f6fa..969351e 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -81,6 +81,7 @@ use std::iter::Peekable; /// assert_eq!(map.get("a").unwrap().get("b").unwrap().get("c").unwrap(), "1"); /// ``` /// +#[derive(Clone, Copy)] pub struct Config { /// Specifies the maximum depth key that `serde_qs` will attempt to /// deserialize. Default is 5. @@ -89,9 +90,14 @@ pub struct Config { strict: bool, } +pub const DEFAULT_CONFIG: Config = Config { + max_depth: 5, + strict: true, +}; + impl Default for Config { fn default() -> Self { - Self::new(5, true) + DEFAULT_CONFIG } } @@ -190,7 +196,7 @@ pub fn from_str<'de, T: de::Deserialize<'de>>(input: &'de str) -> Result<T> { /// A deserializer for the querystring format. /// /// Supported top-level outputs are structs and maps. -pub(crate) struct QsDeserializer<'a> { +pub struct QsDeserializer<'a> { iter: Peekable<IntoIter<Cow<'a, str>, Level<'a>>>, value: Option<Level<'a>>, } @@ -214,9 +220,13 @@ impl<'a> QsDeserializer<'a> { } /// Returns a new `QsDeserializer<'a>`. - fn with_config(config: &Config, input: &'a [u8]) -> Result<Self> { + pub fn with_config(config: &Config, input: &'a [u8]) -> Result<Self> { parse::Parser::new(input, config.max_depth(), config.strict).as_deserializer() } + + pub fn new(input: &'a [u8]) -> Result<Self> { + Self::with_config(&Config::default(), input) + } } impl<'de> de::Deserializer<'de> for QsDeserializer<'de> { |