[−][src]Struct provenance::SeparateProvenanceMap
A ProvenanceMap where the a type separate from the type of the stored values can be used to signify the maps provenance.
This allows for multiple maps that store the values of the same type to be created,
as long as the type given for the Provenance
parameter is unique.
use provenance::{ProvenanceMap, SeparateProvenanceMap}; // Structs that only exist to denote provenance struct One; struct Two; // Creating a map once is OK let mut map = SeparateProvenanceMap::<One, String>::new(); assert!(map.is_some()); // Creating another map is OK as long as the provenance is different let mut map = SeparateProvenanceMap::<Two, String>::new(); assert!(map.is_some());
A ProvenanceMap can be thought of as a special case of this map
where the type of the stored values also is used as provenance. That is
ProvenanceMap<i32> ≈ SeparateProvenanceMap<i32, i32>
. Currently, this is how
ProvenanceMap is implemented. This has the effect that both
types share the available pool of types that can be used as provenance. That
means that both a ProvenanceMap<i32>
and a SeperateProvenanceMap<i32, B>
for any type B
can not be constructed. This beahviour may change in future
versions and should not be relied upon.
use provenance::{ProvenanceMap, SeparateProvenanceMap}; // Creating a map once is OK let mut map = ProvenanceMap::<i32>::new(); assert!(map.is_some()); // Creating another map with the same provenance as another // is not OK, even if that map is a ProvenanceMap let mut map = SeparateProvenanceMap::<i32, bool>::new(); assert!(map.is_none());
Implementations
impl<Provenance: 'static, Value: 'static> SeparateProvenanceMap<Provenance, Value>
[src]
pub fn new() -> Option<SeparateProvenanceMap<Provenance, Value>>
[src]
Creates a new empty map with some type as provenance.
If a map with such provenance already has been created, None
will be returned.
Thus be careful to not drop maps unintentionally.
use provenance::SeparateProvenanceMap; struct Provenance; // Creating a map with some type as provenance is ok let map = SeparateProvenanceMap::<Provenance, bool>::new(); assert!(map.is_some()); // Creating another is not however let map = SeparateProvenanceMap::<Provenance, i32>::new(); assert!(map.is_none());
pub fn insert(&mut self, value: Value) -> Key<Provenance>
[src]
Insert a value into this map. A unique key is returned. The key may be used to retrieve the value.
use provenance::SeparateProvenanceMap; struct Provenance; let mut map = SeparateProvenanceMap::<Provenance, i32>::new().unwrap(); let key = map.insert(5); assert_eq!(&5, map.get(key));
Values are not required to be unique in the map.
use provenance::SeparateProvenanceMap; struct Provenance; let mut map = SeparateProvenanceMap::<Provenance, i32>::new().unwrap(); let key1 = map.insert(5); let key2 = map.insert(5); assert_ne!(key1, key2);
pub fn get(&self, key: Key<Provenance>) -> &Value
[src]
Use a key to retrieve an immutable reference to a stored value.
use provenance::SeparateProvenanceMap; struct Provenance; let mut map = SeparateProvenanceMap::<Provenance, i32>::new().unwrap(); let key = map.insert(5); assert_eq!(&5, map.get(key));
pub fn get_mut(&mut self, key: Key<Provenance>) -> &mut Value
[src]
Use a key to retrieve a mutable reference to a stored value.
use provenance::SeparateProvenanceMap; struct Provenance; let mut map = SeparateProvenanceMap::<Provenance, i32>::new().unwrap(); let key = map.insert(5); assert_eq!(&mut 5, map.get_mut(key));
pub fn keys(&self) -> impl Iterator<Item = Key<Provenance>>
[src]
Get an iterator over all keys in the map.
use provenance::SeparateProvenanceMap; struct Provenance; let mut map = SeparateProvenanceMap::<Provenance, i32>::new().unwrap(); map.insert(1); map.insert(2); map.insert(3); assert_eq!(3, map.keys().count());
pub fn iter(&self) -> impl Iterator<Item = &Value>
[src]
Get an iterator over immutable references to each value in the map.
use provenance::SeparateProvenanceMap; struct Provenance; let mut map = SeparateProvenanceMap::<Provenance, i32>::new().unwrap(); map.insert(1); map.insert(2); map.insert(3); assert_eq!(6, map.iter().sum());
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Value>
[src]
Get an iterator over mutable references to each value in the map.
use provenance::SeparateProvenanceMap; struct Provenance; let mut map = SeparateProvenanceMap::<Provenance, i32>::new().unwrap(); map.insert(1); map.insert(2); map.insert(3); // Add one to every value map.iter_mut().for_each(|val| *val += 1); assert_eq!(9, map.iter().sum());
pub fn find<P: Fn(&Value) -> bool>(&self, predicate: P) -> Option<&Value>
[src]
Search the map in insertion order for the first value that satisfy the given predicate. If such value is found, an immutable reference to it is returned,
use provenance::SeparateProvenanceMap; struct Provenance; let mut map = SeparateProvenanceMap::<Provenance, i32>::new().unwrap(); map.insert(1); map.insert(2); map.insert(3); assert_eq!(Some(&2), map.find(|&val| val == 2));
otherwise None
is returned.
use provenance::SeparateProvenanceMap; struct Provenance; let mut map = SeparateProvenanceMap::<Provenance, i32>::new().unwrap(); map.insert(1); map.insert(2); map.insert(3); assert_eq!(None, map.find(|&val| val == 53));
pub fn find_mut<P: Fn(&Value) -> bool>(
&mut self,
predicate: P
) -> Option<&mut Value>
[src]
&mut self,
predicate: P
) -> Option<&mut Value>
Search the map in insertion order for the first value that satisfy the given predicate. If such value is found, a mutable reference to it is returned,
use provenance::SeparateProvenanceMap; struct Provenance; let mut map = SeparateProvenanceMap::<Provenance, i32>::new().unwrap(); map.insert(1); map.insert(2); map.insert(3); assert_eq!(Some(&mut 2), map.find_mut(|&val| val == 2));
otherwise None
is returned.
use provenance::SeparateProvenanceMap; struct Provenance; let mut map = SeparateProvenanceMap::<Provenance, i32>::new().unwrap(); map.insert(1); map.insert(2); map.insert(3); assert_eq!(None, map.find_mut(|&val| val == 53));
Auto Trait Implementations
impl<Provenance, Value> RefUnwindSafe for SeparateProvenanceMap<Provenance, Value> where
Provenance: RefUnwindSafe,
Value: RefUnwindSafe,
[src]
Provenance: RefUnwindSafe,
Value: RefUnwindSafe,
impl<Provenance, Value> Send for SeparateProvenanceMap<Provenance, Value> where
Provenance: Send,
Value: Send,
[src]
Provenance: Send,
Value: Send,
impl<Provenance, Value> Sync for SeparateProvenanceMap<Provenance, Value> where
Provenance: Sync,
Value: Sync,
[src]
Provenance: Sync,
Value: Sync,
impl<Provenance, Value> Unpin for SeparateProvenanceMap<Provenance, Value> where
Provenance: Unpin,
Value: Unpin,
[src]
Provenance: Unpin,
Value: Unpin,
impl<Provenance, Value> UnwindSafe for SeparateProvenanceMap<Provenance, Value> where
Provenance: UnwindSafe,
Value: UnwindSafe,
[src]
Provenance: UnwindSafe,
Value: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,