diff options
| author | bors <bors@rust-lang.org> | 2013-11-09 00:51:16 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-11-09 00:51:16 -0800 |
| commit | 162ba894bced501e8725c2558447df2403fbd553 (patch) | |
| tree | 8076e688872d20b670930bf6697c99bd7e4828b3 /src/libstd | |
| parent | 785f9b8c16ddf4d122a4e7b65fda6bcc52a44aa0 (diff) | |
| parent | 0865b4d7455009056ff2b94113b02360113a2e96 (diff) | |
| download | rust-162ba894bced501e8725c2558447df2403fbd553.tar.gz rust-162ba894bced501e8725c2558447df2403fbd553.zip | |
auto merge of #10359 : tomassedovic/rust/typeid-iterbytes, r=pcwalton
I'm not sure this is something you're interested in, but I was playing around the Any trait a bit and I wanted to try it as a key in a HashMap. To do that, TypeId needs to implement IterBytes.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/any.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libstd/any.rs b/src/libstd/any.rs index 06f66a014dd..76996c0dede 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; @@ -198,6 +206,13 @@ mod tests { } #[test] + fn type_id_hash() { + let (a, b) = (TypeId::of::<uint>(), TypeId::of::<uint>::()); + + 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); let a_r: &Any = a; |
