Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Commit

Permalink
Use entry api to remove a lookup in deserialisation loop (#438)
Browse files Browse the repository at this point in the history
* Use entry api to remove a lookup in a loop

* cargo fmt
  • Loading branch information
gilescope committed Aug 10, 2021
1 parent c2a069f commit d8a9a98
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/value.rs
Expand Up @@ -15,7 +15,7 @@ use serde::ser;
use crate::datetime::{self, DatetimeFromString};
pub use crate::datetime::{Datetime, DatetimeParseError};

pub use crate::map::Map;
pub use crate::map::{Entry, Map};

/// Representation of a TOML value.
#[derive(PartialEq, Clone, Debug)]
Expand Down Expand Up @@ -526,12 +526,13 @@ impl<'de> de::Deserialize<'de> for Value {
}
let mut map = Map::new();
map.insert(key, visitor.next_value()?);
while let Some(key) = visitor.next_key()? {
if map.contains_key(&key) {
while let Some(key) = visitor.next_key::<String>()? {
if let Entry::Vacant(vacant) = map.entry(&key) {
vacant.insert(visitor.next_value()?);
} else {
let msg = format!("duplicate key: `{}`", key);
return Err(de::Error::custom(msg));
}
map.insert(key, visitor.next_value()?);
}
Ok(Value::Table(map))
}
Expand Down

0 comments on commit d8a9a98

Please sign in to comment.