File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ use std::rand;
65
65
use std:: rand:: Rng ;
66
66
use std:: cmp:: Eq ;
67
67
use std:: cast:: { transmute, transmute_copy} ;
68
+ use std:: to_bytes:: { IterBytes , Cb } ;
68
69
69
70
use serialize:: { Encoder , Encodable , Decoder , Decodable } ;
70
71
@@ -104,6 +105,11 @@ pub struct Uuid {
104
105
/// The 128-bit number stored in 16 bytes
105
106
bytes : UuidBytes
106
107
}
108
+ impl IterBytes for Uuid {
109
+ fn iter_bytes ( & self , _: bool , f : Cb ) -> bool {
110
+ f ( self . bytes . slice_from ( 0 ) )
111
+ }
112
+ }
107
113
108
114
/// A UUID stored as fields (identical to UUID, used only for conversions)
109
115
struct UuidFields {
@@ -796,6 +802,17 @@ mod test {
796
802
let u2 = Decodable :: decode ( & mut ebml:: reader:: Decoder ( doc) ) ;
797
803
assert_eq ! ( u, u2) ;
798
804
}
805
+
806
+ #[ test]
807
+ fn test_iterbytes_impl_for_uuid ( ) {
808
+ use std:: hashmap:: HashSet ;
809
+ let mut set = HashSet :: new ( ) ;
810
+ let id1 = Uuid :: new_v4 ( ) ;
811
+ let id2 = Uuid :: new_v4 ( ) ;
812
+ set. insert ( id1) ;
813
+ assert ! ( set. contains( & id1) ) ;
814
+ assert ! ( !set. contains( & id2) ) ;
815
+ }
799
816
}
800
817
801
818
#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments