Skip to content

Commit

Permalink
extra: impl IterBytes for uuid::Uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
olsonjeffery committed Dec 24, 2013
1 parent 619c4fc commit 41cbbb6
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/libextra/uuid.rs
Expand Up @@ -65,6 +65,7 @@ use std::rand;
use std::rand::Rng;
use std::cmp::Eq;
use std::cast::{transmute,transmute_copy};
use std::to_bytes::{IterBytes, Cb};

use serialize::{Encoder, Encodable, Decoder, Decodable};

Expand Down Expand Up @@ -104,6 +105,11 @@ pub struct Uuid {
/// The 128-bit number stored in 16 bytes
bytes: UuidBytes
}
impl IterBytes for Uuid {
fn iter_bytes(&self, _: bool, f: Cb) -> bool {
f(self.bytes.slice_from(0))
}
}

/// A UUID stored as fields (identical to UUID, used only for conversions)
struct UuidFields {
Expand Down Expand Up @@ -796,6 +802,17 @@ mod test {
let u2 = Decodable::decode(&mut ebml::reader::Decoder(doc));
assert_eq!(u, u2);
}

#[test]
fn test_iterbytes_impl_for_uuid() {
use std::hashmap::HashSet;
let mut set = HashSet::new();
let id1 = Uuid::new_v4();
let id2 = Uuid::new_v4();
set.insert(id1);
assert!(set.contains(&id1));
assert!(!set.contains(&id2));
}
}

#[cfg(test)]
Expand Down

5 comments on commit 41cbbb6

@bors
Copy link
Contributor

@bors bors commented on 41cbbb6 Dec 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at olsonjeffery@41cbbb6

@bors
Copy link
Contributor

@bors bors commented on 41cbbb6 Dec 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging olsonjeffery/rust/master = 41cbbb6 into auto

@bors
Copy link
Contributor

@bors bors commented on 41cbbb6 Dec 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

olsonjeffery/rust/master = 41cbbb6 merged ok, testing candidate = b8c87fd

@bors
Copy link
Contributor

@bors bors commented on 41cbbb6 Dec 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 41cbbb6 Dec 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = b8c87fd

Please sign in to comment.