pub struct WeakSharedContainer<T> { /* private fields */ }
Expand description
A weak reference to a SharedContainer
.
This struct provides an abstraction over different weak reference types:
Weak<std::sync::RwLock<T>>
(used in standard multi-threaded environments)Weak<tokio::sync::RwLock<T>>
(used for async/await support)Weak<RefCell<T>>
(used in single-threaded environments like WebAssembly)
Weak references don’t prevent the value from being dropped when no strong references remain. This helps break reference cycles that could cause memory leaks.
Implementations§
Sourcepub fn upgrade(&self) -> Option<SharedContainer<T>>
pub fn upgrade(&self) -> Option<SharedContainer<T>>
Attempts to create a strong SharedContainer
from this weak reference.
This will succeed if the value has not yet been dropped, i.e., if there are still other strong references to it.
§Returns
Some(SharedContainer<T>)
: If the value still existsNone
: If the value has been dropped
Trait Implementations§
Auto Trait Implementations§
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