pub struct Ephemeron<K: Trace + ?Sized + 'static, V: Trace + 'static> { /* private fields */ }
Expand description
A key-value pair where the value becomes unaccesible when the key is garbage collected.
You can read more about ephemerons on:
- Racket’s page about ephemerons, which gives a brief overview.
- Barry Hayes’ paper “Ephemerons: a new finalization mechanism” which explains the topic in full detail.
Implementations§
source§impl<K: Trace + ?Sized, V: Trace + Clone> Ephemeron<K, V>
impl<K: Trace + ?Sized, V: Trace + Clone> Ephemeron<K, V>
sourcepub fn value(&self) -> Option<V>
pub fn value(&self) -> Option<V>
Gets the stored value of this Ephemeron
, or None
if the key was already garbage collected.
This needs to return a clone of the value because holding a reference to it between garbage collection passes could drop the underlying allocation, causing an Use After Free.
Trait Implementations§
source§impl<K: Debug + Trace + ?Sized + 'static, V: Debug + Trace + 'static> Debug for Ephemeron<K, V>
impl<K: Debug + Trace + ?Sized + 'static, V: Debug + Trace + 'static> Debug for Ephemeron<K, V>
source§impl<K: Trace + ?Sized, V: Trace> Trace for Ephemeron<K, V>
impl<K: Trace + ?Sized, V: Trace> Trace for Ephemeron<K, V>
source§unsafe fn trace_non_roots(&self)
unsafe fn trace_non_roots(&self)
Trace handles located in GC heap, and mark them as non root. Read more
source§fn run_finalizer(&self)
fn run_finalizer(&self)
Runs
Finalize::finalize
on this object and all
contained subobjects.Auto Trait Implementations§
impl<K, V> !RefUnwindSafe for Ephemeron<K, V>
impl<K, V> !Send for Ephemeron<K, V>
impl<K, V> !Sync for Ephemeron<K, V>
impl<K: ?Sized, V> Unpin for Ephemeron<K, V>
impl<K, V> !UnwindSafe for Ephemeron<K, 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