Skip to content

Commit

Permalink
Remove upstream collection traits.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Nov 1, 2014
1 parent 260ea05 commit a6c1e04
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl TypeMap {
self.data.remove(&TypeId::of::<K>())
}

/// 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>, V: 'static>(&'a mut self) -> Entry<'a, K, V> {
match self.data.entry(TypeId::of::<K>()) {
hashmap::Occupied(e) => Occupied(OccupiedEntry { data: e }),
Expand All @@ -79,22 +79,32 @@ impl TypeMap {

/// Get a mutable reference to the underlying HashMap
pub unsafe fn data_mut(&mut self) -> &mut HashMap<TypeId, Box<Any + 'static>> { &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<Any + 'static>>
}

/// 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<Any + 'static>>
}
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit a6c1e04

Please sign in to comment.