diff options
| author | bors <bors@rust-lang.org> | 2013-12-24 01:56:30 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-12-24 01:56:30 -0800 |
| commit | b8c87fd9fe649d3211bb53754fb692a825ecfdff (patch) | |
| tree | 594c22bfd87c9852bdf562820d4e4eadb0ce9220 /src | |
| parent | e09a8e892346ddcb917b74f0c5c678a5b477f609 (diff) | |
| parent | 41cbbb656a9d29305fd03fb09d261cbfa0766f7a (diff) | |
| download | rust-b8c87fd9fe649d3211bb53754fb692a825ecfdff.tar.gz rust-b8c87fd9fe649d3211bb53754fb692a825ecfdff.zip | |
auto merge of #11130 : olsonjeffery/rust/master, r=alexcrichton
So that `Uuid` can be used as the key in a `HashMap` or in a `HashSet`, etc The only question I have about this is: Is endianness an issue, here? If so, what's the correct way to proceed?
Diffstat (limited to 'src')
| -rw-r--r-- | src/libextra/uuid.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libextra/uuid.rs b/src/libextra/uuid.rs index 9e48c3e7a73..cf40a59a8c5 100644 --- a/src/libextra/uuid.rs +++ b/src/libextra/uuid.rs @@ -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}; @@ -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 { @@ -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)] |
