Struct manually_boxed::NoAliasSingleton

source ·
#[non_exhaustive]
pub struct NoAliasSingleton {}
Expand description

Singleton, used for compile-time alias checking

You’ll need one owned one of these, from NoAliasSingleton::init().

Typically, instead of passing &mut NoAliasSingleton to your own sub-functions, you’ll pass TokenMut (or TokenRef, which can be obtained (and copied) with IsTokenRef::token_ref and IsTokenMut::token_mut.

Those token types are zero-sized types, so they incur no runtime cost, even if the compiler can’t figure out that they aren’t ever used.

(NoAliasSingleton is a ZST too, but of course &mut NoAliasSingleton isn’t.)

Implementations§

source§

impl NoAliasSingleton

source

pub unsafe fn init() -> Self

Initialises, by creating the singleton for alias checking

§SAFETY

There must be only one NoAliasSingleton used with each Ptr.

That is, it is unsound to use the same Ptr (or any copy of it) with TokenMutes derived from two (or more) different NoAliasSingletons.

The easiest way to do this is to have only one NoAliasSingleton.

If this rule is violated, borrow and borrow_mut can be instant-UB.

Trait Implementations§

source§

impl Debug for NoAliasSingleton

source§

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

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

impl<'a> IsTokenMut<'a> for &'a mut NoAliasSingleton

source§

fn token_mut<'r>(self) -> TokenMut<'r>
where 'a: 'r,

Obtains a new ZST token from something that might be a real object.
source§

fn as_mut<'r, 's: 'r>(&'s mut self) -> TokenMut<'r>
where 'a: 'r,

Obtains a new ZST token from a borrow that might be of a real object.
source§

fn multi_static<'r>(self) -> MultiStatic<'r, ()>
where 'a: 'r,

Borrows from a small, fixed, number of multiple Ptr Read more
source§

fn multi_dynamic<'r>(self) -> MultiDynamic<'r>
where 'a: 'r,

Borrows from an unknown number of Ptr with dynamic runtime checking Read more
source§

impl<'a> IsTokenRef<'a> for &'a NoAliasSingleton

source§

fn token_ref(self) -> TokenRef<'a>

Obtains a new ZST token from something that might be a real object.
source§

impl<'a> IsTokenRef<'a> for &'a mut NoAliasSingleton

source§

fn token_ref(self) -> TokenRef<'a>

Obtains a new ZST token from something that might be a real object.

Auto Trait Implementations§

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