Skip to content

Commit

Permalink
Add Option<T> deserializer support
Browse files Browse the repository at this point in the history
Signed-off-by: Gris Ge <[email protected]>
  • Loading branch information
cathay4t committed Jan 3, 2025
1 parent fafd671 commit 0163763
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,14 @@ impl<'de> Deserializer<'de> for &mut RmsdDeserializer {
todo!()
}

fn deserialize_option<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
todo!()
match self.parsed.data {
YamlValueData::Null => visitor.visit_none(),
_ => visitor.visit_some(self),
}
}

fn deserialize_unit<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
Expand Down
4 changes: 2 additions & 2 deletions tests/from_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ fn test_de_array_of_enum_of_struct() -> Result<(), RmsdError> {
fn test_de_struct_with_enum_member() -> Result<(), RmsdError> {
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
struct FooTest {
uint_a: EnumTest,
uint_a: Option<EnumTest>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
Expand All @@ -305,7 +305,7 @@ fn test_de_struct_with_enum_member() -> Result<(), RmsdError> {

assert_eq!(
FooTest {
uint_a: EnumTest::Bar(BarTest { uint_b: 32 })
uint_a: Some(EnumTest::Bar(BarTest { uint_b: 32 }))
},
rmsd_yaml::from_str::<FooTest>(
r#"
Expand Down

0 comments on commit 0163763

Please sign in to comment.