Container traits
Container
- A trait to represent the abstract idea of a containerMap
- A map is a key-value store where values may be looked up by their keysMutable
- A trait to represent mutable containersSet
- A set is a group of objects which are each distinct from one anotherContainer
A trait to represent the abstract idea of a container. The only concrete knowledge known is the number of elements contained within.
len
fn len(&self) -> uint
Return the number of elements in the container
is_empty
fn is_empty(&self) -> bool
Return true if the container contains no elements
Map
A map is a key-value store where values may be looked up by their keys. This trait provides basic operations to operate on these stores.
contains_key
fn contains_key(&self, key: &K) -> bool
Return true if the map contains a value for the specified key
find
fn find<'a>(&'a self, key: &K) -> Option<&'a V>
Return a reference to the value corresponding to the key
find_mut
fn find_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V>
Return a mutable reference to the value corresponding to the key
insert
fn insert(&mut self, key: K, value: V) -> bool
Insert a key-value pair into the map. An existing value for a key is replaced by the new value. Return true if the key did not already exist in the map.
remove
fn remove(&mut self, key: &K) -> bool
Remove a key-value pair from the map. Return true if the key was present in the map, otherwise false.
swap
fn swap(&mut self, k: K, v: V) -> Option<V>
Insert a key-value pair from the map. If the key already had a value present in the map, that value is returned. Otherwise None is returned.
pop
fn pop(&mut self, k: &K) -> Option<V>
Removes a key from the map, returning the value at the key if the key was previously in the map.
Mutable
A trait to represent mutable containers
clear
fn clear(&mut self)
Clear the container, removing all values.
Set
A set is a group of objects which are each distinct from one another. This trait represents actions which can be performed on sets to manipulate and iterate over them.
contains
fn contains(&self, value: &T) -> bool
Return true if the set contains a value
insert
fn insert(&mut self, value: T) -> bool
Add a value to the set. Return true if the value was not already present in the set.
remove
fn remove(&mut self, value: &T) -> bool
Remove a value from the set. Return true if the value was present in the set.
is_disjoint
fn is_disjoint(&self, other: &Self) -> bool
Return true if the set has no elements in common with other
. This is equivalent to checking for an empty intersection.
is_subset
fn is_subset(&self, other: &Self) -> bool
Return true if the set is a subset of another
is_superset
fn is_superset(&self, other: &Self) -> bool
Return true if the set is a superset of another
difference
fn difference(&self, other: &Self, f: &fn(&T) -> bool) -> bool
Visit the values representing the difference
symmetric_difference
fn symmetric_difference(&self, other: &Self, f: &fn(&T) -> bool) -> bool
Visit the values representing the symmetric difference
intersection
fn intersection(&self, other: &Self, f: &fn(&T) -> bool) -> bool
Visit the values representing the intersection
union
fn union(&self, other: &Self, f: &fn(&T) -> bool) -> bool
Visit the values representing the union