pub struct Lineage<T> { /* private fields */ }Expand description
A type of cell that allows replacing the contained value without invalidating references to the current value.
Implementations§
Source§impl<T> Lineage<T>
impl<T> Lineage<T>
Sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Gets a mutable reference to the current value.
Performs better than get but requires &mut self.
Sourcepub fn set_mut(&mut self, value: T)
pub fn set_mut(&mut self, value: T)
Replaces the value.
Performs much better than set but requires &mut self. Does not cause a heap
allocation. The implementation is a more optimized version of the following:
fn set_mut<T>(lineage: &mut Lineage<T>, value: T) {
lineage.clear();
*lineage.get_mut() = value;
}Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Drops all past values. Does not affect the current value.
This can only be called if no references to any of the previous values exist anymore. This is
ensured by the &mut self requirement. Should be called as often as possible to avoid having
many past values kept alive unnecessarily.
Sourcepub fn drain(&mut self) -> impl Iterator<Item = T>
pub fn drain(&mut self) -> impl Iterator<Item = T>
Same as clear but returns ownership of past values.
The values are iterated over from newest to oldest. The iterator can safely be dropped, all remaining values in the iterator will be dropped.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Returns ownership of the current value.