extra: implement Encodable/Decodable for Uuid

This commit is contained in:
Corey Richardson 2013-10-14 01:47:52 -04:00
parent 009c3d8bae
commit 023466ccca

View File

@ -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]