Make Travis use its own Rust support and cargo.
[anymap] / src / lib.rs
index 1fae987a0931e41530dd3de0829607ced2c54416..0a1a69224a1622106c872e93196d6d28545bb8da 100644 (file)
@@ -53,7 +53,7 @@ trait UncheckedAnyRefExt<'a> {
     unsafe fn as_ref_unchecked<T: 'static>(self) -> &'a T;
 }
 
-impl<'a> UncheckedAnyRefExt<'a> for &'a Any {
+impl<'a> UncheckedAnyRefExt<'a> for &'a Any + 'a {
     #[inline]
     unsafe fn as_ref_unchecked<T: 'static>(self) -> &'a T {
         // Get the raw representation of the trait object
@@ -71,7 +71,7 @@ trait UncheckedAnyMutRefExt<'a> {
     unsafe fn as_mut_unchecked<T: 'static>(self) -> &'a mut T;
 }
 
-impl<'a> UncheckedAnyMutRefExt<'a> for &'a mut Any {
+impl<'a> UncheckedAnyMutRefExt<'a> for &'a mut Any + 'a {
     #[inline]
     unsafe fn as_mut_unchecked<T: 'static>(self) -> &'a mut T {
         // Get the raw representation of the trait object
@@ -102,13 +102,13 @@ impl<'a> UncheckedAnyMutRefExt<'a> for &'a mut Any {
 /// assert_eq!(data.find::<Foo>(), None);
 /// data.insert(Foo { str: "foo".to_string() });
 /// assert_eq!(data.find(), Some(&Foo { str: "foo".to_string() }));
-/// data.find_mut::<Foo>().map(|foo| foo.str.push_char('t'));
+/// data.find_mut::<Foo>().map(|foo| foo.str.push('t'));
 /// assert_eq!(data.find::<Foo>().unwrap().str.as_slice(), "foot");
 /// ```
 ///
 /// Values containing non-static references are not permitted.
 pub struct AnyMap {
-    data: HashMap<TypeId, Box<Any>, TypeIdHasher>,
+    data: HashMap<TypeId, Box<Any + 'static>, TypeIdHasher>,
 }
 
 impl AnyMap {
@@ -141,6 +141,11 @@ impl AnyMap {
     pub fn remove<T: 'static>(&mut self) {
         self.data.remove(&TypeId::of::<T>());
     }
+
+    /// Does a value of type `T` exist?
+    pub fn contains<T: 'static>(&self) -> bool {
+        self.data.contains_key(&TypeId::of::<T>())
+    }
 }
 
 impl Collection for AnyMap {