Skip to content

Commit 78df42d

Browse files
authored
Support deserialization into newtype structs (#141)
1 parent fce4b46 commit 78df42d

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/src/types/serde/typ.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl<'de> Deserializer<'de> for BoltTypeDeserializer<'de> {
367367
BoltType::DateTimeZoneId(dtz) if name == "Timezone" => {
368368
visitor.visit_newtype_struct(BorrowedStrDeserializer::new(dtz.tz_id()))
369369
}
370-
_ => self.unexpected(visitor),
370+
_ => visitor.visit_newtype_struct(self),
371371
}
372372
}
373373

@@ -2169,4 +2169,25 @@ mod tests {
21692169

21702170
assert_eq!(actual, Frobnicate::Foo);
21712171
}
2172+
2173+
#[test]
2174+
fn deserialize_tuple_struct() {
2175+
#[derive(Deserialize, Debug)]
2176+
pub struct MyString(String);
2177+
2178+
#[derive(Deserialize, Debug)]
2179+
pub struct MyThing {
2180+
my_string: MyString,
2181+
}
2182+
2183+
let value = BoltType::from("Frobnicate");
2184+
let value = [(BoltString::from("my_string"), value)]
2185+
.into_iter()
2186+
.collect::<BoltMap>();
2187+
let value = BoltType::Map(value);
2188+
2189+
let actual = value.to::<MyThing>().unwrap();
2190+
2191+
assert_eq!(actual.my_string.0, "Frobnicate");
2192+
}
21722193
}

0 commit comments

Comments
 (0)