Skip to main content

SideTable

Struct SideTable 

Source
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>

Source

pub fn new() -> Self

Source

pub fn with_teardown(teardown: impl Fn(V) + 'static) -> Self

A table whose values need active teardown when their view goes away.

Source

pub fn insert(&self, key: usize, value: V) -> Option<V>

Source

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).

Source

pub fn take(&self, key: usize) -> Option<V>

Remove without running the teardown hook (the caller takes ownership).

Source

pub fn contains(&self, key: usize) -> bool

Source

pub fn get(&self, key: usize) -> Option<V>
where V: Clone,

Source

pub fn with<R>(&self, key: usize, f: impl FnOnce(&mut V) -> R) -> Option<R>

Run f on the value in place (returns None if absent).

Source

pub fn for_each(&self, f: impl FnMut(usize, &V))

Run f over every (key, value) (immutable; do not re-enter this table).

Trait Implementations§

Source§

impl<V> Default for SideTable<V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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>
where Rc<RefCell<HashMap<usize, V>>>: Freeze, Option<Rc<dyn Fn(V)>>: Freeze,

§

impl<V> Unpin for SideTable<V>
where Rc<RefCell<HashMap<usize, V>>>: Unpin, Option<Rc<dyn Fn(V)>>: Unpin,

§

impl<V> UnsafeUnpin for SideTable<V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.