Aliasable

Struct Aliasable 

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

An unboxed aliasable value.

Implementations§

Source§

impl<T> Aliasable<T>

Source

pub fn new(val: T) -> Self

Create a new Aliasable that stores val.

Source

pub fn get(self: Pin<&Self>) -> &T

Get a shared reference to the value inside the Aliasable.

This method takes Pin<&Self> instead of &self to enforce that all parent containers are !Unpin, and thus won’t be annotated with noalias.

This crate intentionally does not provide a method to get an &mut T, because the value may be shared. To obtain an &mut T you should use an interior mutable container such as a mutex or UnsafeCell.

Source

pub unsafe fn get_extended<'a>(self: Pin<&Self>) -> &'a T

Get a shared reference to the value inside the Aliasable with an extended lifetime.

§Safety

The reference must not be held for longer than the Aliasable exists.

Source

pub fn into_inner(self) -> T

Consume the Aliasable, returning its inner value.

If get has already been called and the type is now pinned, obtaining the owned Aliasable<T> required to call this function requires breaking the pinning guarantee (as the Aliasable<T> is moved). However, this is sound as long as the Aliasable<T> isn’t actually aliased at that point in time.

Trait Implementations§

Source§

impl<T> Debug for Aliasable<T>

Source§

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

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

impl<T: Default> Default for Aliasable<T>

Source§

fn default() -> Aliasable<T>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<T> !Unpin for Aliasable<T>

§

impl<T> UnwindSafe for Aliasable<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<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.