@@ -30,16 +30,16 @@ pub trait Mutable: Container {
30
30
31
31
/// A map is a key-value store where values may be looked up by their keys. This
32
32
/// trait provides basic operations to operate on these stores.
33
- pub trait Map < K , V > : Mutable {
33
+ pub trait Map < K , V > : Container {
34
34
/// Return true if the map contains a value for the specified key
35
35
fn contains_key ( & self , key : & K ) -> bool ;
36
36
37
37
/// Return a reference to the value corresponding to the key
38
38
fn find < ' a > ( & ' a self , key : & K ) -> Option < & ' a V > ;
39
+ }
39
40
40
- /// Return a mutable reference to the value corresponding to the key
41
- fn find_mut < ' a > ( & ' a mut self , key : & K ) -> Option < & ' a mut V > ;
42
-
41
+ /// This trait provides basic operations to modify the contents of a map.
42
+ pub trait MutableMap < K , V > : Map < K , V > + Mutable {
43
43
/// Insert a key-value pair into the map. An existing value for a
44
44
/// key is replaced by the new value. Return true if the key did
45
45
/// not already exist in the map.
@@ -56,23 +56,18 @@ pub trait Map<K, V>: Mutable {
56
56
/// Removes a key from the map, returning the value at the key if the key
57
57
/// was previously in the map.
58
58
fn pop ( & mut self , k : & K ) -> Option < V > ;
59
+
60
+ /// Return a mutable reference to the value corresponding to the key
61
+ fn find_mut < ' a > ( & ' a mut self , key : & K ) -> Option < & ' a mut V > ;
59
62
}
60
63
61
64
/// A set is a group of objects which are each distinct from one another. This
62
- /// trait represents actions which can be performed on sets to manipulate and
63
- /// iterate over them.
64
- pub trait Set < T > : Mutable {
65
+ /// trait represents actions which can be performed on sets to iterate over
66
+ /// them.
67
+ pub trait Set < T > : Container {
65
68
/// Return true if the set contains a value
66
69
fn contains ( & self , value : & T ) -> bool ;
67
70
68
- /// Add a value to the set. Return true if the value was not already
69
- /// present in the set.
70
- fn insert ( & mut self , value : T ) -> bool ;
71
-
72
- /// Remove a value from the set. Return true if the value was
73
- /// present in the set.
74
- fn remove ( & mut self , value : & T ) -> bool ;
75
-
76
71
/// Return true if the set has no elements in common with `other`.
77
72
/// This is equivalent to checking for an empty intersection.
78
73
fn is_disjoint ( & self , other : & Self ) -> bool ;
@@ -95,3 +90,15 @@ pub trait Set<T>: Mutable {
95
90
/// Visit the values representing the union
96
91
fn union ( & self , other : & Self , f : & fn ( & T ) -> bool ) -> bool ;
97
92
}
93
+
94
+ /// This trait represents actions which can be performed on sets to mutate
95
+ /// them.
96
+ pub trait MutableSet < T > : Set < T > + Mutable {
97
+ /// Add a value to the set. Return true if the value was not already
98
+ /// present in the set.
99
+ fn insert ( & mut self , value : T ) -> bool ;
100
+
101
+ /// Remove a value from the set. Return true if the value was
102
+ /// present in the set.
103
+ fn remove ( & mut self , value : & T ) -> bool ;
104
+ }
0 commit comments