diff options
author | Sam Scott <sam.scott89@gmail.com> | 2017-05-21 13:21:09 +0100 |
---|---|---|
committer | Sam Scott <sam.scott89@gmail.com> | 2017-05-21 13:21:09 +0100 |
commit | 54578d5302e8ad23ba7a9ec8996514721299006f (patch) | |
tree | 303c78e526e12a5a727642a0edc977244de54791 /src/de | |
parent | cdfdac80ff65ffb1c18df3da1534ea652a63dd40 (diff) |
Add stricter lints.
Diffstat (limited to 'src/de')
-rw-r--r-- | src/de/mod.rs | 8 | ||||
-rw-r--r-- | src/de/parse.rs | 20 |
2 files changed, 15 insertions, 13 deletions
diff --git a/src/de/mod.rs b/src/de/mod.rs index 0f3aa10..03e4065 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -145,10 +145,8 @@ pub fn from_reader<'de, T, R>(mut reader: R) -> Result<T> R: Read, { let mut buf = vec![]; - reader.read_to_end(&mut buf) - .map_err(|e| { - ErrorKind::Io(e) - })?; + let _ = reader.read_to_end(&mut buf) + .map_err(Error::from)?; from_bytes(&buf) } @@ -177,7 +175,7 @@ impl QsDeserializer { } /// Returns a new `QsDeserializer`. - fn with_config(config: &Config, input: &[u8]) -> Self { + pub fn with_config(config: &Config, input: &[u8]) -> Self { let decoded = percent_encoding::percent_decode(input); parse::Parser::new(decoded, vec![], None, config.max_depth()).as_deserializer() diff --git a/src/de/parse.rs b/src/de/parse.rs index 1d5e5a8..74d31a5 100644 --- a/src/de/parse.rs +++ b/src/de/parse.rs @@ -40,39 +40,41 @@ impl Default for Config { } impl Config { + /// Construct a new `Config` with the specified maximum depth of nesting. pub fn with_max_depth(depth: usize) -> Config { Config { max_depth: depth } } + /// Get maximum depth parameter. pub fn max_depth(&self) -> usize { self.max_depth } } impl Config { + /// Deserializes a querystring from a `&[u8]` using this `Config`. pub fn deserialize_bytes<'de, T: de::Deserialize<'de>>(&self, input: &[u8]) -> Result<T> { T::deserialize(QsDeserializer::with_config(self, input)) } + /// Deserializes a querystring from a `&str` using this `Config`. pub fn deserialize_str<'de, T: de::Deserialize<'de>>(&self, input: &str) -> Result<T> { self.deserialize_bytes(input.as_bytes()) } + /// Deserializes a querystring from a reader using this `Config`. pub fn deserialize_reader<'de, T, R>(&self, mut reader: R) -> Result<T> where T: de::Deserialize<'de>, R: Read, { let mut buf = vec![]; - reader.read_to_end(&mut buf) - .map_err(|e| { - ErrorKind::Io(e) - })?; + let _ = reader.read_to_end(&mut buf).map_err(Error::from)?; self.deserialize_bytes(&buf) } } @@ -111,15 +113,17 @@ fn insert_into_map(node: &mut Level, key: String, value: String) { if let Level::Nested(ref mut map) = *node { match map.entry(key) { Entry::Occupied(mut o) => { - o.insert(Level::Invalid("Multiple values for one key")); + // Throw away old result; map is now invalid anyway. + let _ = o.insert(Level::Invalid("Multiple values for one key")); }, Entry::Vacant(vm) => { - vm.insert(Level::Flat(value)); + // Map is empty, result is None + let _ = vm.insert(Level::Flat(value)); }, } } else { let mut map = BTreeMap::default(); - map.insert(key, Level::Flat(value)); + let _ = map.insert(key, Level::Flat(value)); *node = Level::Nested(map); } } @@ -141,7 +145,7 @@ impl<I: Iterator<Item = u8>> Parser<I> { } let iter = match root { Level::Nested(map) => map.into_iter(), - _ => panic!("root node should never be able to converted to anything else. Something went seriously wrong."), + _ => BTreeMap::default().into_iter() }; QsDeserializer { iter: iter, |