pub struct Ref<'a, T: ?Sized> { /* private fields */ }Expand description
Shared (immutable) borrow guard for account data.
On drop, decrements the borrow count in RuntimeAccount.borrow_state.
Implementations§
Source§impl<'a, T: ?Sized> Ref<'a, T>
impl<'a, T: ?Sized> Ref<'a, T>
Sourcepub fn map<U: ?Sized>(orig: Self, f: impl FnOnce(&T) -> &U) -> Ref<'a, U>
pub fn map<U: ?Sized>(orig: Self, f: impl FnOnce(&T) -> &U) -> Ref<'a, U>
Narrow a guard to a field or slice without releasing its account borrow.
Sourcepub fn try_map<U: ?Sized, E>(
orig: Self,
f: impl FnOnce(&T) -> Result<&U, E>,
) -> Result<Ref<'a, U>, (Self, E)>
pub fn try_map<U: ?Sized, E>( orig: Self, f: impl FnOnce(&T) -> Result<&U, E>, ) -> Result<Ref<'a, U>, (Self, E)>
Narrow a guard, returning the original guard and error on failure.
Sourcepub fn filter_map<U: ?Sized>(
orig: Self,
f: impl FnOnce(&T) -> Option<&U>,
) -> Result<Ref<'a, U>, Self>
pub fn filter_map<U: ?Sized>( orig: Self, f: impl FnOnce(&T) -> Option<&U>, ) -> Result<Ref<'a, U>, Self>
Narrow a guard, returning the original guard if the field is absent.
Sourcepub unsafe fn from_raw_parts(value: &'a T, state: *mut u8) -> Self
pub unsafe fn from_raw_parts(value: &'a T, state: *mut u8) -> Self
Create a shared borrow guard from raw parts.
§Safety
The caller must ensure:
- The borrow state at
statewas already incremented valueis valid for lifetime'astatepoints to a validRuntimeAccount.borrow_state
Sourcepub fn into_raw_parts(self) -> (&'a T, *mut u8)
pub fn into_raw_parts(self) -> (&'a T, *mut u8)
Decompose into raw parts without running the destructor.
The caller takes responsibility for eventually releasing the
borrow (decrementing *state).
Trait Implementations§
Auto Trait Implementations§
impl<'a, T> !Send for Ref<'a, T>
impl<'a, T> !Sync for Ref<'a, T>
impl<'a, T> Freeze for Ref<'a, T>
impl<'a, T> RefUnwindSafe for Ref<'a, T>
impl<'a, T> Unpin for Ref<'a, T>
impl<'a, T> UnsafeUnpin for Ref<'a, T>
impl<'a, T> UnwindSafe for Ref<'a, T>
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