moveit::slot

Struct Slot

Source
pub struct Slot<'frame, T> { /* private fields */ }
Expand description

An empty slot on the stack into which a value could be emplaced.

The 'frame lifetime refers to the lifetime of the stack frame this Slot’s storage is allocated on.

See slot!() and the module documentation.

Implementations§

Source§

impl<'frame, T> Slot<'frame, T>

Source

pub unsafe fn new_unchecked( ptr: &'frame mut MaybeUninit<T>, drop_flag: DropFlag<'frame>, ) -> Self

Creates a new Slot with the given pointer as its basis.

To safely construct a Slot, use slot!().

§Safety

ptr must not be outlived by any other pointers to its allocation.

drop_flag’s value must be dead, and must be a drop flag governing the destruction of ptr’s storage in an appropriate manner as described in moveit::drop_flag.

Source

pub fn put(self, val: T) -> MoveRef<'frame, T>

Put val into this slot, returning a new MoveRef.

Source

pub fn pin(self, val: T) -> Pin<MoveRef<'frame, T>>

Pin val into this slot, returning a new, pinned MoveRef.

Source

pub fn emplace<N: New<Output = T>>(self, new: N) -> Pin<MoveRef<'frame, T>>

Emplace new into this slot, returning a new, pinned MoveRef.

Source

pub fn try_emplace<N: TryNew<Output = T>>( self, new: N, ) -> Result<Pin<MoveRef<'frame, T>>, N::Error>

Try to emplace new into this slot, returning a new, pinned MoveRef.

Source

pub fn into_pinned(self) -> Slot<'frame, Pin<T>>

Converts this into a slot for a pinned T.

This is safe, since this Slot owns the referenced data, and Pin is explicitly a repr(transparent) type.

Source

pub unsafe fn cast<U>(self) -> Slot<'frame, U>

Converts this Slot from being a slot for a T to being a slot for some other type U.

moveit::slot!(place: u32);
let foo: MoveRef<u16> = unsafe { place.cast::<u16>() }.put(42);
§Safety

T must have at least the size and alignment as U.

Source§

impl<'frame, T> Slot<'frame, Pin<T>>

Source

pub fn into_unpinned(self) -> Slot<'frame, T>

Converts this into a slot for an unpinned T.

This is safe, since this Slot owns the referenced data, and Pin is explicitly a repr(transparent) type.

Moreover, no actual unpinning is occurring: the referenced data must be uninitialized, so it cannot have a pinned referent.

Auto Trait Implementations§

§

impl<'frame, T> Freeze for Slot<'frame, T>

§

impl<'frame, T> !RefUnwindSafe for Slot<'frame, T>

§

impl<'frame, T> !Send for Slot<'frame, T>

§

impl<'frame, T> !Sync for Slot<'frame, T>

§

impl<'frame, T> Unpin for Slot<'frame, T>

§

impl<'frame, T> !UnwindSafe for Slot<'frame, T>

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.