pub struct Ref<T: ?Sized> { /* private fields */ }Expand description
Implementations§
Source§impl<T: ?Sized> Ref<T>
impl<T: ?Sized> Ref<T>
Sourcepub fn try_borrow_mut<'rc>(&'rc self) -> Result<Borrow<'rc, T>, BorrowError>
pub fn try_borrow_mut<'rc>(&'rc self) -> Result<Borrow<'rc, T>, BorrowError>
Sourcepub fn try_borrow_mut_or_else<'rc, E>(
&'rc self,
err_borrowed: impl FnOnce() -> E,
err_dropped: impl FnOnce() -> E,
) -> Result<Borrow<'rc, T>, E>
pub fn try_borrow_mut_or_else<'rc, E>( &'rc self, err_borrowed: impl FnOnce() -> E, err_dropped: impl FnOnce() -> E, ) -> Result<Borrow<'rc, T>, E>
Tries to borrow the data mutably and returns a custom error if borrowing fails.
Sourcepub fn try_access_mut<R, F: FnOnce(&mut T) -> R>(
&self,
op: F,
) -> Result<R, BorrowError>
pub fn try_access_mut<R, F: FnOnce(&mut T) -> R>( &self, op: F, ) -> Result<R, BorrowError>
Provides access to the data through a closure.
If the data is already borrowed or the owning RefBox is dropped,
the closure is not executed and an error is returned. Otherwise, the
closure is executed and the output of the closure is returned.
§Returns
Ok(R)if the access was successfulErr(BorrowError::Borrowed)if the data was already borrowedErr(BorrowError::Dropped)if the owningRefBoxwas dropped
Sourcepub fn try_clone(&self) -> Option<Ref<T>>
pub fn try_clone(&self) -> Option<Ref<T>>
Tries to clone the weak reference to the data.
§Returns
Some(Ref)if it was succesful.Noneif the number of weaks overflowedu32::MAX.
Sourcepub fn refcount(&self) -> u32
pub fn refcount(&self) -> u32
Returns the number of Refs that point to the same data as this Ref.
Sourcepub fn is_borrowed(&self) -> bool
pub fn is_borrowed(&self) -> bool
Returns true if the data is currently mutably borrowed.
Sourcepub fn is(&self, owner: &RefBox<T>) -> bool
pub fn is(&self, owner: &RefBox<T>) -> bool
Returns true if this Ref and the supplied RefBox
point to the same instance.
Sourcepub unsafe fn get_unchecked(&self) -> &T
pub unsafe fn get_unchecked(&self) -> &T
Returns an immutable reference to the data without checking if the data is already mutably borrowed or dropped.
§Safety
- Ensure there are no mutable references to
T. - Ensure
Tis fully initialized (don’t use this inRefBox::new_cyclic). - Ensure the owning
RefBoxis alive for the entire lifetime of the returned reference.
Sourcepub unsafe fn get_mut_unchecked(&mut self) -> &mut T
pub unsafe fn get_mut_unchecked(&mut self) -> &mut T
Returns a mutable reference to the data without checking if the data is already mutably borrowed or dropped.
§Safety
- Ensure there are no other references to
T. - Ensure
Tis fully initialized (don’t use this inRefBox::new_cyclic). - Ensure the owning
RefBoxis alive for the entire lifetime of the returned reference.