Enabled Cargo and moved Makefile to use target.
[anymap] / src / lib.rs
index 01297b8c8e8dba517764fe670ff615475b0e6fe5..b67731966952329e32591fc45b1dee86797440f1 100644 (file)
@@ -6,14 +6,14 @@
 #![feature(default_type_params)]
 #![warn(unnecessary_qualification, non_uppercase_statics,
         variant_size_difference, managed_heap_memory, unnecessary_typecast,
-        missing_doc, unused_result, deprecated_owned_vector)]
+        missing_doc, unused_result)]
 
 #[cfg(test)]
 extern crate test;
 
 use std::any::Any;
 use std::intrinsics::TypeId;
-use std::collections::HashMap;
+use std::collections::{Collection, HashMap, Mutable};
 use std::hash::{Hash, Hasher, Writer};
 use std::mem::{transmute, transmute_copy};
 use std::raw::TraitObject;
@@ -109,7 +109,7 @@ impl<'a> UncheckedAnyMutRefExt<'a> for &'a mut Any {
 ///
 /// Values containing non-static references are not permitted.
 pub struct AnyMap {
-    data: HashMap<TypeId, Box<Any>:'static, TypeIdHasher>,
+    data: HashMap<TypeId, Box<Any>, TypeIdHasher>,
 }
 
 impl AnyMap {
@@ -135,7 +135,7 @@ impl AnyMap {
     /// Set the value contained in the map for the type `T`.
     /// This will override any previous value stored.
     pub fn insert<T: 'static>(&mut self, value: T) {
-        self.data.insert(TypeId::of::<T>(), box value as Box<Any>:'static);
+        self.data.insert(TypeId::of::<T>(), box value as Box<Any>);
     }
 
     /// Remove the value for the type `T` if it existed.
@@ -144,6 +144,22 @@ impl AnyMap {
     }
 }
 
+impl Collection for AnyMap {
+    fn len(&self) -> uint {
+        self.data.len()
+    }
+
+    fn is_empty(&self) -> bool {
+        self.data.is_empty()
+    }
+}
+
+impl Mutable for AnyMap {
+    fn clear(&mut self) {
+        self.data.clear();
+    }
+}
+
 #[bench]
 fn bench_insertion(b: &mut ::test::Bencher) {
     b.iter(|| {