Skip to content

Commit 023466c

Browse files
committed
extra: implement Encodable/Decodable for Uuid
1 parent 009c3d8 commit 023466c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/libextra/uuid.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ use std::rand::Rng;
6666
use std::cmp::Eq;
6767
use std::cast::{transmute,transmute_copy};
6868

69+
use serialize::{Encoder, Encodable, Decoder, Decodable};
70+
6971
/// A 128-bit (16 byte) buffer containing the ID
7072
pub type UuidBytes = [u8, ..16];
7173

@@ -486,6 +488,19 @@ impl TotalEq for Uuid {
486488
}
487489
}
488490

491+
// FIXME #9845: Test these
492+
impl<T: Encoder> Encodable<T> for Uuid {
493+
fn encode(&self, e: &mut T) {
494+
e.emit_str(self.to_hyphenated_str());
495+
}
496+
}
497+
498+
impl<T: Decoder> Decodable<T> for Uuid {
499+
fn decode(d: &mut T) -> Uuid {
500+
from_str(d.read_str()).unwrap()
501+
}
502+
}
503+
489504
/// Generates a random instance of UUID (V4 conformant)
490505
impl rand::Rand for Uuid {
491506
#[inline]

0 commit comments

Comments
 (0)