File tree 3 files changed +26
-15
lines changed
3 files changed +26
-15
lines changed Original file line number Diff line number Diff line change @@ -208,15 +208,6 @@ impl<'de> Deserializer<'de> {
208
208
where
209
209
V : serde:: de:: Visitor < ' de > ,
210
210
{
211
- if let DeserializerHint :: BinarySubtype ( expected_st) = hint {
212
- if self . current_type != ElementType :: Binary {
213
- return Err ( Error :: custom ( format ! (
214
- "expected Binary with subtype {:?}, instead got {:?}" ,
215
- expected_st, self . current_type
216
- ) ) ) ;
217
- }
218
- }
219
-
220
211
match self . current_type {
221
212
ElementType :: Int32 => visitor. visit_i32 ( read_i32 ( & mut self . bytes ) ?) ,
222
213
ElementType :: Int64 => visitor. visit_i64 ( read_i64 ( & mut self . bytes ) ?) ,
Original file line number Diff line number Diff line change @@ -637,13 +637,12 @@ impl Deserializer {
637
637
638
638
let is_rawbson = matches ! ( hint, DeserializerHint :: RawBson ) ;
639
639
640
- if let DeserializerHint :: BinarySubtype ( expected_st) = hint {
641
- match value {
642
- Bson :: Binary ( ref b) if b. subtype == expected_st => { }
643
- ref b => {
640
+ if let DeserializerHint :: BinarySubtype ( expected_subtype) = hint {
641
+ if let Bson :: Binary ( ref binary) = value {
642
+ if binary. subtype != expected_subtype {
644
643
return Err ( Error :: custom ( format ! (
645
- "expected Binary with subtype {:?}, instead got {:?}" ,
646
- expected_st , b
644
+ "expected Binary with subtype {:?}, instead got subtype {:?}" ,
645
+ expected_subtype , binary . subtype
647
646
) ) ) ;
648
647
}
649
648
}
Original file line number Diff line number Diff line change 1
1
use crate :: {
2
+ from_document,
3
+ from_slice,
2
4
spec:: BinarySubtype ,
3
5
uuid:: { Uuid , UuidRepresentation } ,
4
6
Binary ,
@@ -269,3 +271,22 @@ fn interop_1() {
269
271
let d_uuid = doc ! { "uuid" : uuid_uuid } ;
270
272
assert_eq ! ( d_bson, d_uuid) ;
271
273
}
274
+
275
+ #[ test]
276
+ fn deserialize_uuid_from_string ( ) {
277
+ #[ derive( Deserialize ) ]
278
+ struct UuidWrapper {
279
+ uuid : Uuid ,
280
+ }
281
+
282
+ let uuid = Uuid :: new ( ) ;
283
+
284
+ let doc = doc ! { "uuid" : uuid. to_string( ) } ;
285
+ let wrapper: UuidWrapper = from_document ( doc) . expect ( "failed to deserialize document" ) ;
286
+ assert_eq ! ( wrapper. uuid, uuid) ;
287
+
288
+ let raw_doc = rawdoc ! { "uuid" : uuid. to_string( ) } ;
289
+ let wrapper: UuidWrapper =
290
+ from_slice ( raw_doc. as_bytes ( ) ) . expect ( "failed to deserialize raw document" ) ;
291
+ assert_eq ! ( wrapper. uuid, uuid) ;
292
+ }
You can’t perform that action at this time.
0 commit comments