@@ -25,10 +25,10 @@ use std::fmt::{self, Display, Debug};
2525
2626use chrono:: { DateTime , Timelike , UTC } ;
2727use chrono:: offset:: TimeZone ;
28+ use data_encoding:: hex;
2829
2930use oid;
3031use ordered:: OrderedDocument ;
31- use rustc_serialize:: hex:: { FromHex , ToHex } ;
3232use serde_json:: Value ;
3333use spec:: { ElementType , BinarySubtype } ;
3434
@@ -80,7 +80,7 @@ impl Debug for Bson {
8080
8181 write ! ( f, "TimeStamp({}, {})" , time, inc)
8282 }
83- & Bson :: Binary ( t, ref vec) => write ! ( f, "BinData({}, 0x{})" , u8 :: from( t) , vec . to_hex ( ) ) ,
83+ & Bson :: Binary ( t, ref vec) => write ! ( f, "BinData({}, 0x{})" , u8 :: from( t) , hex :: encode ( vec ) ) ,
8484 & Bson :: ObjectId ( ref id) => write ! ( f, "ObjectId({:?})" , id) ,
8585 & Bson :: UtcDatetime ( date_time) => write ! ( f, "UtcDatetime({:?})" , date_time) ,
8686 & Bson :: Symbol ( ref sym) => write ! ( f, "Symbol({:?})" , sym) ,
@@ -123,7 +123,7 @@ impl Display for Bson {
123123 write ! ( fmt, "Timestamp({}, {})" , time, inc)
124124 }
125125 & Bson :: Binary ( t, ref vec) => {
126- write ! ( fmt, "BinData({}, 0x{})" , u8 :: from( t) , vec . to_hex ( ) )
126+ write ! ( fmt, "BinData({}, 0x{})" , u8 :: from( t) , hex :: encode ( vec ) )
127127 }
128128 & Bson :: ObjectId ( ref id) => write ! ( fmt, "ObjectId(\" {}\" )" , id) ,
129129 & Bson :: UtcDatetime ( date_time) => write ! ( fmt, "Date(\" {}\" )" , date_time) ,
@@ -301,7 +301,7 @@ impl Bson {
301301 let tval: u8 = From :: from ( t) ;
302302 json ! ( {
303303 "type" : tval,
304- "$binary" : v . to_hex ( )
304+ "$binary" : hex :: encode ( v )
305305 } )
306306 } ,
307307 & Bson :: ObjectId ( ref v) => json ! ( { "$oid" : v. to_string( ) } ) ,
@@ -365,7 +365,7 @@ impl Bson {
365365 Bson :: Binary ( t, ref v) => {
366366 let tval: u8 = From :: from ( t) ;
367367 doc ! {
368- "$binary" => ( v . to_hex ( ) ) ,
368+ "$binary" => ( hex :: encode ( v ) ) ,
369369 "type" => ( tval as i64 )
370370 }
371371 }
@@ -409,7 +409,7 @@ impl Bson {
409409
410410 } else if let ( Ok ( hex) , Ok ( t) ) = ( values. get_str ( "$binary" ) , values. get_i64 ( "type" ) ) {
411411 let ttype = t as u8 ;
412- return Bson :: Binary ( From :: from ( ttype) , hex. from_hex ( ) . unwrap ( ) ) ;
412+ return Bson :: Binary ( From :: from ( ttype) , hex:: decode ( hex . to_uppercase ( ) . as_bytes ( ) ) . unwrap ( ) ) ;
413413 }
414414
415415 } else if values. len ( ) == 1 {
0 commit comments