From 0865b4d7455009056ff2b94113b02360113a2e96 Mon Sep 17 00:00:00 2001 From: Tomas Sedovic Date: Fri, 8 Nov 2013 17:30:35 +0100 Subject: [PATCH] Implement IterBytes for TypeId --- src/libstd/any.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libstd/any.rs b/src/libstd/any.rs index 06f66a014ddee..76996c0dede28 100644 --- a/src/libstd/any.rs +++ b/src/libstd/any.rs @@ -14,6 +14,7 @@ use cast::transmute; use cmp::Eq; use option::{Option, Some, None}; +use to_bytes::{IterBytes, Cb}; use to_str::ToStr; use unstable::intrinsics; use util::Void; @@ -42,6 +43,12 @@ impl Eq for TypeId { } } +impl IterBytes for TypeId { + fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { + self.t.iter_bytes(lsb0, f) + } +} + /////////////////////////////////////////////////////////////////////////////// // Any trait /////////////////////////////////////////////////////////////////////////////// @@ -175,6 +182,7 @@ mod tests { use super::*; use super::AnyRefExt; use option::{Some, None}; + use hash::Hash; #[deriving(Eq)] struct Test; @@ -197,6 +205,13 @@ mod tests { assert_eq!(c, f); } + #[test] + fn type_id_hash() { + let (a, b) = (TypeId::of::(), TypeId::of::::()); + + assert_eq!(a.hash(), b.hash()); + } + #[test] fn any_as_void_ptr() { let (a, b, c) = (~5u as ~Any, ~TEST as ~Any, ~Test as ~Any);