Struct Slot

Source
pub struct Slot<'a, T: ?Sized = Void>(/* private fields */);
Expand description

A memory block used to store arbitrary objects.

Implementations§

Source§

impl<'a> Slot<'a>

Source

pub unsafe fn new_unchecked(ptr: NonNull<u8>) -> Self

Creates a new slot from the supplied pointer.

§Safety
  • The returned instance may not be used outside of construct.
  • Constructs will write objects directly to the address of ptr, hence ptr must meet all safety requirements of construct.
Source

pub unsafe fn write_unchecked<T>(self, object: T) -> NonNull<T>

Consumes this slot, filling it with the supplied object.

§Safety

The object may not have a different layout than the one returned from PinConstruct::layout.

Source

pub unsafe fn cast<T>(self) -> Slot<'a, T>

Transforms this slot into a typed one.

§Safety

The layout of T must match that from PinConstruct::layout exactly.

Source§

impl<'a, T> Slot<'a, T>

Source

pub fn write(self, object: T) -> &'a mut Opaque<T>

Consumes this slot, filling it with the supplied object.

The returned object is sealed in Opaque to prevent misuse. Despite this, as demonstrated below, it’s still possible to coerce it into a trait object:

fn fill_slot(slot: Slot<String>) -> &mut Opaque<dyn Any> {
    slot.write(String::from("WRYYY!")) as &mut Opaque<dyn Any>
}
Source§

impl<'a, T: ?Sized> Slot<'a, T>

Source

pub fn into_raw(self) -> NonNull<u8>

Consumes this instance, returning a raw pointer to the allocated memory block.

Trait Implementations§

Source§

impl<T: ?Sized> Debug for Slot<'_, T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for Slot<'a, T>
where T: ?Sized,

§

impl<'a, T> RefUnwindSafe for Slot<'a, T>
where T: RefUnwindSafe + ?Sized,

§

impl<'a, T = Void> !Send for Slot<'a, T>

§

impl<'a, T = Void> !Sync for Slot<'a, T>

§

impl<'a, T> Unpin for Slot<'a, T>
where T: ?Sized,

§

impl<'a, T = Void> !UnwindSafe for Slot<'a, 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.