diff options
| author | Corey Richardson <corey@octayn.net> | 2013-10-14 01:47:52 -0400 |
|---|---|---|
| committer | Corey Richardson <corey@octayn.net> | 2013-10-14 01:47:55 -0400 |
| commit | 023466cccaf2230b6f2beb3e9e9802e6be1f29d9 (patch) | |
| tree | d4258db7f60b444e205124690e620655237cd3a9 | |
| parent | 009c3d8bae1c12d36c77649dde90523b708b8d10 (diff) | |
| download | rust-023466cccaf2230b6f2beb3e9e9802e6be1f29d9.tar.gz rust-023466cccaf2230b6f2beb3e9e9802e6be1f29d9.zip | |
extra: implement Encodable/Decodable for Uuid
| -rw-r--r-- | src/libextra/uuid.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libextra/uuid.rs b/src/libextra/uuid.rs index a219b8fb557..c3b67ae0a0c 100644 --- a/src/libextra/uuid.rs +++ b/src/libextra/uuid.rs @@ -66,6 +66,8 @@ use std::rand::Rng; use std::cmp::Eq; use std::cast::{transmute,transmute_copy}; +use serialize::{Encoder, Encodable, Decoder, Decodable}; + /// A 128-bit (16 byte) buffer containing the ID pub type UuidBytes = [u8, ..16]; @@ -486,6 +488,19 @@ impl TotalEq for Uuid { } } +// FIXME #9845: Test these +impl<T: Encoder> Encodable<T> for Uuid { + fn encode(&self, e: &mut T) { + e.emit_str(self.to_hyphenated_str()); + } +} + +impl<T: Decoder> Decodable<T> for Uuid { + fn decode(d: &mut T) -> Uuid { + from_str(d.read_str()).unwrap() + } +} + /// Generates a random instance of UUID (V4 conformant) impl rand::Rand for Uuid { #[inline] |
