Struct AssertSafe

Source
pub struct AssertSafe<T> { /* private fields */ }
Expand description

A type for pointers that cannot uphold the necessary guard invariants at the type level, but which can be assumed to behave properly by unsafe code.

Implementations§

Source§

impl<T> AssertSafe<T>
where T: Deref,

Source

pub unsafe fn new_unchecked(inner: T) -> Self

Wrap a general-purpose pointer into a wrapper that implements the Guarded (and potentially GuardedMut) traits, provided that the pointer upholds this invariants anyway.

§Safety

For the guard invariants to be upheld, the pointer must:

  • dereference into a stable location. This forbids types that implement Deref by borrowing data that they own without a heap-based container in between;
  • be owned. Any type that has a shorter lifetime than 'static, may have its borrow cancelled at any time, with the original borrowed data accessible again.

Trait Implementations§

Source§

impl<T: Debug> Debug for AssertSafe<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, U> Guarded for AssertSafe<T>
where T: Deref<Target = U>, U: ?Sized,

Source§

type Target = U

The target pointee that this pointer may dereference into. There are no real restrictions to what this type can be. However, the user must not assume that simply because a &Target reference is protected, that references indirectly derived (via Deref and other traits) would also be protected.
Source§

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

Borrow the pointee, into a fixed reference that can be sent directly and safely to e.g. memory-sharing completion-based I/O interfaces. Read more
Source§

impl<T, U> GuardedMut for AssertSafe<T>
where T: Deref<Target = U> + DerefMut, U: ?Sized,

Source§

fn borrow_guarded_mut(&mut self) -> &mut Self::Target

Borrow the pointee mutably, into a fixed reference that can be sent directly and safely to e.g. memory-sharing completion-based I/O interfaces. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for AssertSafe<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> GuardedExt for T
where T: Guarded,

Source§

fn map<F, T>(this: Self, f: F) -> Mapped<Self, T>
where F: FnOnce(&<Self as Guarded>::Target) -> &T, T: ?Sized,

Apply a function to the pointee, creating a new guarded type that dereferences into the result of that function. Read more
Source§

fn try_map<F, T, E>(this: Self, f: F) -> Result<Mapped<Self, T>, E>
where F: FnOnce(&<Self as Guarded>::Target) -> Result<&T, E>, T: ?Sized,

Apply a fallible function to the pointee, creating a new guarded type that dereferences into the result of that function. Read more
Source§

impl<T> GuardedMutExt for T
where T: GuardedMut,

Source§

fn map_mut<F, T>(this: Self, f: F) -> MappedMut<Self, T>
where F: FnOnce(&mut <Self as Guarded>::Target) -> &mut T, T: ?Sized,

Apply a function to the pointee, creating a new guarded type that dereferences into the result of that function. Read more
Source§

fn try_map_mut<F, T, E>(this: Self, f: F) -> Result<MappedMut<Self, T>, E>
where F: FnOnce(&mut <Self as Guarded>::Target) -> Result<&mut T, E>, T: ?Sized,

Apply a fallible function to the pointee, creating a new guarded type that dereferences into the result of that function. Read more
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<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.