pub struct DormantMutRef<'a, T> {
    ptr: NonNull<T>,
    _marker: PhantomData<&'a mut T>,
}
Expand description

Models a reborrow of some unique reference, when you know that the reborrow and all its descendants (i.e., all pointers and references derived from it) will not be used any more at some point, after which you want to use the original unique reference again.

The borrow checker usually handles this stacking of borrows for you, but some control flows that accomplish this stacking are too complicated for the compiler to follow. A DormantMutRef allows you to check borrowing yourself, while still expressing its stacked nature, and encapsulating the raw pointer code needed to do this without undefined behavior.

Fields§

§ptr: NonNull<T>§_marker: PhantomData<&'a mut T>

Implementations§

source§

impl<'a, T> DormantMutRef<'a, T>

source

pub fn new(t: &'a mut T) -> (&'a mut T, Self)

Capture a unique borrow, and immediately reborrow it. For the compiler, the lifetime of the new reference is the same as the lifetime of the original reference, but you promise to use it for a shorter period.

source

pub unsafe fn awaken(self) -> &'a mut T

Revert to the unique borrow initially captured.

Safety

The reborrow must have ended, i.e., the reference returned by new and all pointers and references derived from it, must not be used anymore.

source

pub unsafe fn reborrow(&mut self) -> &'a mut T

Borrows a new mutable reference from the unique borrow initially captured.

Safety

The reborrow must have ended, i.e., the reference returned by new and all pointers and references derived from it, must not be used anymore.

source

pub unsafe fn reborrow_shared(&self) -> &'a T

Borrows a new shared reference from the unique borrow initially captured.

Safety

The reborrow must have ended, i.e., the reference returned by new and all pointers and references derived from it, must not be used anymore.

Trait Implementations§

source§

impl<'a, T> Send for DormantMutRef<'a, T>where &'a mut T: Send,

source§

impl<'a, T> Sync for DormantMutRef<'a, T>where &'a mut T: Sync,

Auto Trait Implementations§

§

impl<'a, T> RefUnwindSafe for DormantMutRef<'a, T>where T: RefUnwindSafe,

§

impl<'a, T> Unpin for DormantMutRef<'a, T>

§

impl<'a, T> !UnwindSafe for DormantMutRef<'a, T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.