Skip to content

Commit ee9166e

Browse files
committed
Revise comments on the FlatMapDeserializer entry taker
1 parent b5a9eff commit ee9166e

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

serde/src/private/de.rs

+16-17
Original file line numberDiff line numberDiff line change
@@ -2750,8 +2750,8 @@ where
27502750
where
27512751
V: Visitor<'de>,
27522752
{
2753-
for item in self.0.iter_mut() {
2754-
if let Some((key, value)) = use_item(item, variants) {
2753+
for entry in self.0.iter_mut() {
2754+
if let Some((key, value)) = flat_map_take_entry(entry, variants) {
27552755
return visitor.visit_enum(EnumDeserializer::new(key, Some(value)));
27562756
}
27572757
}
@@ -2902,8 +2902,8 @@ where
29022902
where
29032903
T: DeserializeSeed<'de>,
29042904
{
2905-
for item in self.iter.by_ref() {
2906-
if let Some((key, content)) = use_item(item, self.fields) {
2905+
for entry in self.iter.by_ref() {
2906+
if let Some((key, content)) = flat_map_take_entry(entry, self.fields) {
29072907
self.pending_content = Some(content);
29082908
return seed.deserialize(ContentDeserializer::new(key)).map(Some);
29092909
}
@@ -2922,24 +2922,23 @@ where
29222922
}
29232923
}
29242924

2925-
/// Checks if first element of the specified pair matches one of the key from
2926-
/// `keys` parameter and if this is true, takes it from the option and returns.
2927-
/// Otherwise, or if `item` already empty, returns `None`.
2925+
/// Claims one key-value pair from a FlatMapDeserializer's field buffer if the
2926+
/// field name matches any of the recognized ones.
29282927
#[cfg(any(feature = "std", feature = "alloc"))]
2929-
fn use_item<'de>(
2930-
item: &mut Option<(Content<'de>, Content<'de>)>,
2931-
keys: &[&str],
2928+
fn flat_map_take_entry<'de>(
2929+
entry: &mut Option<(Content<'de>, Content<'de>)>,
2930+
recognized: &[&str],
29322931
) -> Option<(Content<'de>, Content<'de>)> {
2933-
// items in the vector are nulled out when used. So we can only use
2934-
// an item if it's still filled in and if the field is one we care
2935-
// about.
2936-
let use_item = match *item {
2932+
// Entries in the FlatMapDeserializer buffer are nulled out as they get
2933+
// claimed for deserialization. We only use an entry if it is still present
2934+
// and if the field is one recognized by the current data structure.
2935+
let is_recognized = match entry {
29372936
None => false,
2938-
Some((ref c, _)) => c.as_str().map_or(false, |key| keys.contains(&key)),
2937+
Some((k, _v)) => k.as_str().map_or(false, |name| recognized.contains(&name)),
29392938
};
29402939

2941-
if use_item {
2942-
item.take()
2940+
if is_recognized {
2941+
entry.take()
29432942
} else {
29442943
None
29452944
}

0 commit comments

Comments
 (0)