pub struct SideTable<V: 'static> { /* private fields */ }Expand description
A pointer-keyed map swept automatically by crate::sidetable::sweep. Construct inside a
thread_local! initializer; the optional teardown hook runs for each removed
value (release a retained native object, dispose an owned child, …), both on sweep
and on plain SideTable::remove, so teardown cannot be bypassed by accident.
Implementations§
Source§impl<V> SideTable<V>
impl<V> SideTable<V>
pub fn new() -> Self
Sourcepub fn with_teardown(teardown: impl Fn(V) + 'static) -> Self
pub fn with_teardown(teardown: impl Fn(V) + 'static) -> Self
A table whose values need active teardown when their view goes away.
pub fn insert(&self, key: usize, value: V) -> Option<V>
Sourcepub fn remove(&self, key: usize) -> Option<V>
pub fn remove(&self, key: usize) -> Option<V>
Remove and tear down the entry (returns None always when a teardown hook
exists, because the value is consumed by it; use SideTable::take to skip it).
Sourcepub fn take(&self, key: usize) -> Option<V>
pub fn take(&self, key: usize) -> Option<V>
Remove without running the teardown hook (the caller takes ownership).
pub fn contains(&self, key: usize) -> bool
pub fn get(&self, key: usize) -> Option<V>where
V: Clone,
Trait Implementations§
Auto Trait Implementations§
impl<V> !RefUnwindSafe for SideTable<V>
impl<V> !Send for SideTable<V>
impl<V> !Sync for SideTable<V>
impl<V> !UnwindSafe for SideTable<V>
impl<V> Freeze for SideTable<V>
impl<V> Unpin for SideTable<V>
impl<V> UnsafeUnpin for SideTable<V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more