summaryrefslogtreecommitdiff
path: root/src/de
diff options
context:
space:
mode:
Diffstat (limited to 'src/de')
-rw-r--r--src/de/mod.rs16
-rw-r--r--src/de/parse.rs4
2 files changed, 15 insertions, 5 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> {
diff --git a/src/de/parse.rs b/src/de/parse.rs
index 0080d02..3be7aa2 100644
--- a/src/de/parse.rs
+++ b/src/de/parse.rs
@@ -184,7 +184,7 @@ impl<'a> Iterator for Parser<'a> {
}
}
-impl<'a> Parser<'a> {
+impl Parser<'_> {
#[inline]
fn peek(&mut self) -> Option<<Self as Iterator>::Item> {
if self.peeked.is_some() {
@@ -268,7 +268,7 @@ impl<'a> Parser<'a> {
Cow::Owned(owned) => Ok(Cow::Owned(owned)),
};
self.clear_acc();
- ret.map_err(Error::from)
+ ret
}
/// In some ways the main way to use a `Parser`, this runs the parsing step