diff --git a/src/lib.rs b/src/lib.rs index 236db35..2405352 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,7 +66,7 @@ impl TypeMap { self.data.remove(&TypeId::of::()) } - /// Gets the given key's corresponding entry in the map for in-place manipulation. + /// Get the given key's corresponding entry in the map for in-place manipulation. pub fn entry<'a, K: Assoc, V: 'static>(&'a mut self) -> Entry<'a, K, V> { match self.data.entry(TypeId::of::()) { hashmap::Occupied(e) => Occupied(OccupiedEntry { data: e }), @@ -79,22 +79,32 @@ impl TypeMap { /// Get a mutable reference to the underlying HashMap pub unsafe fn data_mut(&mut self) -> &mut HashMap> { &mut self.data } + + /// Get the number of values stored in the map. + pub fn len(&self) -> uint { + self.data.len() + } + + /// Remove all entries from the map. + pub fn clear(&mut self) { + self.data.clear() + } } -/// A view onto an entry in the map. +/// A view onto an entry in a TypeMap. pub enum Entry<'a, K, V> { - /// A view onto an occupied entry in the map. + /// A view onto an occupied entry in a TypeMap. Occupied(OccupiedEntry<'a, K, V>), - /// A view onto an unoccupied entry in the map. + /// A view onto an unoccupied entry in a TypeMap. Vacant(VacantEntry<'a, K, V>) } -/// A view onto an occupied entry in the map. +/// A view onto an occupied entry in a TypeMap. pub struct OccupiedEntry<'a, K, V> { data: hashmap::OccupiedEntry<'a, TypeId, Box> } -/// A view onto an unoccupied entry in the map. +/// A view onto an unoccupied entry in a TypeMap. pub struct VacantEntry<'a, K, V> { data: hashmap::VacantEntry<'a, TypeId, Box> } @@ -145,18 +155,6 @@ impl<'a, K, V: 'static> VacantEntry<'a, K, V> { } } -impl Collection for TypeMap { - fn len(&self) -> uint { - self.data.len() - } -} - -impl Mutable for TypeMap { - fn clear(&mut self) { - self.data.clear() - } -} - #[cfg(test)] mod test { use super::{TypeMap, Assoc, Occupied, Vacant};