Skip to content

Commit 25414bf

Browse files
committed
Merge pull request #8 from michaelsproul/collections-reform
Remove upstream collection traits.
2 parents 9132442 + 10587f0 commit 25414bf

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/lib.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![license = "MIT"]
2-
#![deny(missing_doc)]
2+
#![deny(missing_docs)]
33
#![deny(warnings)]
44

55
//! A type-based key value store where one value type is allowed for each key.
@@ -66,7 +66,7 @@ impl TypeMap {
6666
self.data.remove(&TypeId::of::<K>())
6767
}
6868

69-
/// Gets the given key's corresponding entry in the map for in-place manipulation.
69+
/// Get the given key's corresponding entry in the map for in-place manipulation.
7070
pub fn entry<'a, K: Assoc<V>, V: 'static>(&'a mut self) -> Entry<'a, K, V> {
7171
match self.data.entry(TypeId::of::<K>()) {
7272
hashmap::Occupied(e) => Occupied(OccupiedEntry { data: e }),
@@ -79,22 +79,37 @@ impl TypeMap {
7979

8080
/// Get a mutable reference to the underlying HashMap
8181
pub unsafe fn data_mut(&mut self) -> &mut HashMap<TypeId, Box<Any + 'static>> { &mut self.data }
82+
83+
/// Get the number of values stored in the map.
84+
pub fn len(&self) -> uint {
85+
self.data.len()
86+
}
87+
88+
/// Return true if the map contains no values.
89+
pub fn is_empty(&self) -> bool {
90+
self.data.is_empty()
91+
}
92+
93+
/// Remove all entries from the map.
94+
pub fn clear(&mut self) {
95+
self.data.clear()
96+
}
8297
}
8398

84-
/// A view onto an entry in the map.
99+
/// A view onto an entry in a TypeMap.
85100
pub enum Entry<'a, K, V> {
86-
/// A view onto an occupied entry in the map.
101+
/// A view onto an occupied entry in a TypeMap.
87102
Occupied(OccupiedEntry<'a, K, V>),
88-
/// A view onto an unoccupied entry in the map.
103+
/// A view onto an unoccupied entry in a TypeMap.
89104
Vacant(VacantEntry<'a, K, V>)
90105
}
91106

92-
/// A view onto an occupied entry in the map.
107+
/// A view onto an occupied entry in a TypeMap.
93108
pub struct OccupiedEntry<'a, K, V> {
94109
data: hashmap::OccupiedEntry<'a, TypeId, Box<Any + 'static>>
95110
}
96111

97-
/// A view onto an unoccupied entry in the map.
112+
/// A view onto an unoccupied entry in a TypeMap.
98113
pub struct VacantEntry<'a, K, V> {
99114
data: hashmap::VacantEntry<'a, TypeId, Box<Any + 'static>>
100115
}
@@ -145,18 +160,6 @@ impl<'a, K, V: 'static> VacantEntry<'a, K, V> {
145160
}
146161
}
147162

148-
impl Collection for TypeMap {
149-
fn len(&self) -> uint {
150-
self.data.len()
151-
}
152-
}
153-
154-
impl Mutable for TypeMap {
155-
fn clear(&mut self) {
156-
self.data.clear()
157-
}
158-
}
159-
160163
#[cfg(test)]
161164
mod test {
162165
use super::{TypeMap, Assoc, Occupied, Vacant};

0 commit comments

Comments
 (0)