Skip to main content

Guarded

Struct Guarded 

Source
#[repr(transparent)]
pub struct Guarded<T> { pub borrow: T, /* private fields */ }
Expand description

A borrow guarded by an invariant.

This is used to define GuardedBorrow. This can also be used to define the equivalent of GuardedBorrow with smart pointers, like RefMut.

Fields§

§borrow: T

Borrow contained in this guard.

The T type parameter is meant to be a mutable borrow type (like &mut T, or RefMut<T>).

Implementations§

Source§

impl<T> Guarded<T>

Source

pub fn guard(self) -> Mapping<T, bool>

The guard associated with this borrow.

The type invariant of the Guarded ensures that the current value of borrow satisfies this guard.

logic(open, inline)

*self._guard

Source§

impl<'a, T: ?Sized> Guarded<&'a mut T>

Source

pub fn new(borrow: &'a mut T, guard: Snapshot<Mapping<T, bool>>) -> Self

Create a new guarded borrow.

The borrow contained in the result is guaranteed to satisfy the guard at the end of its lifetime.

Note that the borrow field cannot have its final value changed, ensuring that it will not get swapped for another borrow.

ensures

result.borrow == borrow

ensures

forall<bor: &mut T> result.guard()[bor] == (guard[*bor] && ^bor == ^borrow)

ensures

guard[^borrow]

ghost

Source

pub fn into_shared(self) -> &'a T

Get a shared borrow out of this guarded borrow.

It is not possible to break the guard anymore, since the returned borrow is immutable.

ensures

*result == *self.borrow

ensures

*self.borrow == ^self.borrow

ghost

Trait Implementations§

Source§

impl<T> Deref for Guarded<T>

Source§

fn deref(&self) -> &Self::Target

ensures

*result == self.borrow

ghost

Source§

type Target = T

The resulting type after dereferencing.
Source§

impl<T> Drop for Guarded<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Guarded<T>
where T: Freeze,

§

impl<T> Objective for Guarded<T>
where T: Objective,

§

impl<T> RefUnwindSafe for Guarded<T>
where T: RefUnwindSafe,

§

impl<T> Send for Guarded<T>
where T: Send,

§

impl<T> Sync for Guarded<T>
where T: Sync,

§

impl<T> Unpin for Guarded<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Guarded<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Guarded<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.