pub struct WeakIdentityMap { /* private fields */ }Expand description
A weak-reference based identity map that allows objects to be garbage collected.
This variant uses Weak<RwLock<>> instead of Arc<RwLock<>>, allowing
objects to be dropped when no external references remain. The map
automatically cleans up stale entries on access.
Implementations§
Source§impl WeakIdentityMap
impl WeakIdentityMap
Sourcepub fn register<M: Model + 'static>(
&mut self,
arc: &Arc<RwLock<Box<dyn Any + Send + Sync>>>,
pk_values: &[Value],
)
pub fn register<M: Model + 'static>( &mut self, arc: &Arc<RwLock<Box<dyn Any + Send + Sync>>>, pk_values: &[Value], )
Register an object in the weak identity map.
The map holds a weak reference; when all strong references are dropped, the object can be garbage collected.
Sourcepub fn get<M: Model + Clone + Send + Sync + 'static>(
&self,
pk_values: &[Value],
) -> Option<Arc<RwLock<Box<dyn Any + Send + Sync>>>>
pub fn get<M: Model + Clone + Send + Sync + 'static>( &self, pk_values: &[Value], ) -> Option<Arc<RwLock<Box<dyn Any + Send + Sync>>>>
Try to get an object from the weak map.
Returns None if the object was never registered or has been dropped.
Trait Implementations§
Source§impl Default for WeakIdentityMap
impl Default for WeakIdentityMap
Source§fn default() -> WeakIdentityMap
fn default() -> WeakIdentityMap
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for WeakIdentityMap
impl RefUnwindSafe for WeakIdentityMap
impl Send for WeakIdentityMap
impl Sync for WeakIdentityMap
impl Unpin for WeakIdentityMap
impl UnsafeUnpin for WeakIdentityMap
impl UnwindSafe for WeakIdentityMap
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).