pub struct WeakInstance { /* private fields */ }Expand description
Weak reference to an Instance.
This is a weak handle that does not prevent the Instance from being dropped. Dependent objects (Database, Sync, BackgroundSync) hold weak references to avoid circular reference cycles that would leak memory.
Use upgrade() to convert to a strong Instance reference.
Implementations§
Source§impl WeakInstance
impl WeakInstance
Sourcepub fn upgrade(&self) -> Option<Instance>
pub fn upgrade(&self) -> Option<Instance>
Upgrade to a strong reference.
Attempts to upgrade this weak reference to a strong Instance reference.
Returns None if the Instance has already been dropped.
§Returns
Some(Instance) if the Instance still exists, None otherwise.
§Example
let instance = Instance::open(Box::new(InMemory::new()))?;
let weak = instance.downgrade();
// Upgrade works while instance exists
assert!(weak.upgrade().is_some());
drop(instance);
// Upgrade fails after instance is dropped
assert!(weak.upgrade().is_none());Trait Implementations§
Source§impl Clone for WeakInstance
impl Clone for WeakInstance
Source§fn clone(&self) -> WeakInstance
fn clone(&self) -> WeakInstance
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for WeakInstance
impl Debug for WeakInstance
Auto Trait Implementations§
impl Freeze for WeakInstance
impl !RefUnwindSafe for WeakInstance
impl Send for WeakInstance
impl Sync for WeakInstance
impl Unpin for WeakInstance
impl !UnwindSafe for WeakInstance
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