pub struct TrackingDict<K, V> { /* private fields */ }Expand description
A HashMap wrapper that records which keys have been mutated.
Implementations§
Source§impl<K, V> TrackingDict<K, V>
impl<K, V> TrackingDict<K, V>
Sourcepub fn from_map(data: HashMap<K, V>) -> Self
pub fn from_map(data: HashMap<K, V>) -> Self
Create a TrackingDict pre-populated with data.
None of the initial keys are considered dirty.
Sourcepub fn get(&self, key: &K) -> Option<&V>
pub fn get(&self, key: &K) -> Option<&V>
Returns a reference to the value for the given key, if present.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns true if the map contains the key.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
Iterate over all (key, value) pairs. Not tracked.
Sourcepub fn inner(&self) -> &HashMap<K, V>
pub fn inner(&self) -> &HashMap<K, V>
Returns a reference to the underlying HashMap. Not tracked.
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Insert a key-value pair. Marks key as dirty.
Sourcepub fn remove(&mut self, key: &K) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
Remove a key. Marks key as dirty if it was present.
Sourcepub fn set_default(&mut self, key: K, default: V) -> &mut Vwhere
V: Clone,
pub fn set_default(&mut self, key: K, default: V) -> &mut Vwhere
V: Clone,
Like HashMap::entry, but marks the key as dirty on any insertion.
Sourcepub fn update_no_track(&mut self, other: HashMap<K, V>)
pub fn update_no_track(&mut self, other: HashMap<K, V>)
Merge entries from other without marking any key as dirty.
Equivalent to Python’s update_no_track.
Sourcepub fn mark_as_accessed(&mut self, key: K)
pub fn mark_as_accessed(&mut self, key: K)
Manually mark a key as dirty so it appears in the next drain.
Sourcepub fn pop_accessed_keys(&mut self) -> HashSet<K>
pub fn pop_accessed_keys(&mut self) -> HashSet<K>
Drain and return all keys that have been written to since the last call to this method (or since construction).
Sourcepub fn pop_accessed_write_items(&mut self) -> Vec<(K, EntryValue<V>)>where
V: Clone,
pub fn pop_accessed_write_items(&mut self) -> Vec<(K, EntryValue<V>)>where
V: Clone,
Drain dirty keys together with their current values.
If a key was deleted, the value is EntryValue::Deleted.
Trait Implementations§
Source§impl<K: Clone, V: Clone> Clone for TrackingDict<K, V>
impl<K: Clone, V: Clone> Clone for TrackingDict<K, V>
Source§fn clone(&self) -> TrackingDict<K, V>
fn clone(&self) -> TrackingDict<K, V>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more