1
1
#![ license = "MIT" ]
2
- #![ deny( missing_doc ) ]
2
+ #![ deny( missing_docs ) ]
3
3
#![ deny( warnings) ]
4
4
5
5
//! A type-based key value store where one value type is allowed for each key.
@@ -66,7 +66,7 @@ impl TypeMap {
66
66
self . data . remove ( & TypeId :: of :: < K > ( ) )
67
67
}
68
68
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.
70
70
pub fn entry < ' a , K : Assoc < V > , V : ' static > ( & ' a mut self ) -> Entry < ' a , K , V > {
71
71
match self . data . entry ( TypeId :: of :: < K > ( ) ) {
72
72
hashmap:: Occupied ( e) => Occupied ( OccupiedEntry { data : e } ) ,
@@ -79,22 +79,37 @@ impl TypeMap {
79
79
80
80
/// Get a mutable reference to the underlying HashMap
81
81
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
+ }
82
97
}
83
98
84
- /// A view onto an entry in the map .
99
+ /// A view onto an entry in a TypeMap .
85
100
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 .
87
102
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 .
89
104
Vacant ( VacantEntry < ' a , K , V > )
90
105
}
91
106
92
- /// A view onto an occupied entry in the map .
107
+ /// A view onto an occupied entry in a TypeMap .
93
108
pub struct OccupiedEntry < ' a , K , V > {
94
109
data : hashmap:: OccupiedEntry < ' a , TypeId , Box < Any + ' static > >
95
110
}
96
111
97
- /// A view onto an unoccupied entry in the map .
112
+ /// A view onto an unoccupied entry in a TypeMap .
98
113
pub struct VacantEntry < ' a , K , V > {
99
114
data : hashmap:: VacantEntry < ' a , TypeId , Box < Any + ' static > >
100
115
}
@@ -145,18 +160,6 @@ impl<'a, K, V: 'static> VacantEntry<'a, K, V> {
145
160
}
146
161
}
147
162
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
-
160
163
#[ cfg( test) ]
161
164
mod test {
162
165
use super :: { TypeMap , Assoc , Occupied , Vacant } ;
0 commit comments