Skip to content

Commit

Permalink
fix(serde): Allow newtypes for keys
Browse files Browse the repository at this point in the history
Fixes #586
  • Loading branch information
epage committed Sep 26, 2023
1 parent 1bdf123 commit a376cfd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 0 additions & 1 deletion crates/toml/tests/testsuite/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,6 @@ fn newtype_variant() {
}

#[test]
#[should_panic = "invalid type: string \"x\", expected tuple struct NewType"]
fn newtype_key() {
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Serialize, Deserialize)]
struct NewType(String);
Expand Down
13 changes: 12 additions & 1 deletion crates/toml_edit/src/de/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,20 @@ impl<'de> serde::de::Deserializer<'de> for KeyDeserializer {
self.deserialize_any(visitor)
}

fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Error>
where
V: serde::de::Visitor<'de>,
{
visitor.visit_newtype_struct(self)
}

serde::forward_to_deserialize_any! {
bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string seq
bytes byte_buf map option unit newtype_struct
bytes byte_buf map option unit
ignored_any unit_struct tuple_struct tuple identifier
}
}
Expand Down

0 comments on commit a376cfd

Please sign in to comment.