File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ use std::rand;
6565use std:: rand:: Rng ;
6666use std:: cmp:: Eq ;
6767use std:: cast:: { transmute, transmute_copy} ;
68+ use std:: to_bytes:: { IterBytes , Cb } ;
6869
6970use serialize:: { Encoder , Encodable , Decoder , Decodable } ;
7071
@@ -104,6 +105,11 @@ pub struct Uuid {
104105 /// The 128-bit number stored in 16 bytes
105106 bytes : UuidBytes
106107}
108+ impl IterBytes for Uuid {
109+ fn iter_bytes ( & self , _: bool , f : Cb ) -> bool {
110+ f ( self . bytes . slice_from ( 0 ) )
111+ }
112+ }
107113
108114/// A UUID stored as fields (identical to UUID, used only for conversions)
109115struct UuidFields {
@@ -796,6 +802,17 @@ mod test {
796802 let u2 = Decodable :: decode ( & mut ebml:: reader:: Decoder ( doc) ) ;
797803 assert_eq ! ( u, u2) ;
798804 }
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+ }
799816}
800817
801818#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments