Add contains method for checking if a type is already in the map.
authorJonathan Reem <jonathan.reem@gmail.com>
committerJonathan Reem <jonathan.reem@gmail.com>
src/lib.rs

index 1fae987a0931e41530dd3de0829607ced2c54416..0c71e367ab39814bb219a547cce50ef7bdc46a9e 100644 (file)
@@ -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 {