Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #365 from dtolnay/empty
Browse files Browse the repository at this point in the history
Allow empty document to be deserialized using visit_none
  • Loading branch information
dtolnay committed Apr 5, 2023
2 parents 8353dbf + 0d98534 commit 2a25cb7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ impl<'de, 'document> de::Deserializer<'de> for &mut DeserializerFromEvents<'de,
}
Event::SequenceEnd => panic!("unexpected end of sequence"),
Event::MappingEnd => panic!("unexpected end of mapping"),
Event::Void => break Err(error::new(ErrorImpl::EndOfStream)),
Event::Void => break visitor.visit_none(),
}
}
// The de::Error impl creates errors with unknown line and column. Fill
Expand Down
8 changes: 8 additions & 0 deletions tests/test_de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,14 @@ fn test_no_required_fields() {
let expected = BTreeMap::new();
let deserialized: BTreeMap<char, usize> = serde_yaml::from_str(document).unwrap();
assert_eq!(expected, deserialized);

let expected = None;
let deserialized: Option<String> = serde_yaml::from_str(document).unwrap();
assert_eq!(expected, deserialized);

let expected = Value::Null;
let deserialized: Value = serde_yaml::from_str(document).unwrap();
assert_eq!(expected, deserialized);
}
}

Expand Down

0 comments on commit 2a25cb7

Please sign in to comment.