File tree Expand file tree Collapse file tree 3 files changed +26
-15
lines changed Expand file tree Collapse file tree 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> {
208208 where
209209 V : serde:: de:: Visitor < ' de > ,
210210 {
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-
220211 match self . current_type {
221212 ElementType :: Int32 => visitor. visit_i32 ( read_i32 ( & mut self . bytes ) ?) ,
222213 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 {
637637
638638 let is_rawbson = matches ! ( hint, DeserializerHint :: RawBson ) ;
639639
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 {
644643 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
647646 ) ) ) ;
648647 }
649648 }
Original file line number Diff line number Diff line change 11use crate :: {
2+ from_document,
3+ from_slice,
24 spec:: BinarySubtype ,
35 uuid:: { Uuid , UuidRepresentation } ,
46 Binary ,
@@ -269,3 +271,22 @@ fn interop_1() {
269271 let d_uuid = doc ! { "uuid" : uuid_uuid } ;
270272 assert_eq ! ( d_bson, d_uuid) ;
271273}
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