diff --git a/crates/toml/tests/testsuite/serde.rs b/crates/toml/tests/testsuite/serde.rs index 82ba00b1..d9d7a6db 100644 --- a/crates/toml/tests/testsuite/serde.rs +++ b/crates/toml/tests/testsuite/serde.rs @@ -742,6 +742,25 @@ fn newtype_variant() { } } +#[test] +fn newtype_key() { + #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Serialize, Deserialize)] + struct NewType(String); + + type CustomKeyMap = std::collections::BTreeMap; + + equivalent! { + [ + (NewType("x".to_owned()), 1), + (NewType("y".to_owned()), 2), + ].into_iter().collect::(), + map! { + x: Value::Integer(1), + y: Value::Integer(2) + }, + } +} + #[derive(Debug, Default, PartialEq, Serialize, Deserialize)] struct CanBeEmpty { a: Option, diff --git a/crates/toml_edit/src/de/key.rs b/crates/toml_edit/src/de/key.rs index 3da41df4..a3b28256 100644 --- a/crates/toml_edit/src/de/key.rs +++ b/crates/toml_edit/src/de/key.rs @@ -62,9 +62,20 @@ impl<'de> serde::de::Deserializer<'de> for KeyDeserializer { self.deserialize_any(visitor) } + fn deserialize_newtype_struct( + self, + _name: &'static str, + visitor: V, + ) -> Result + 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 } }