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>
impl<'a> Slot<'a>
Sourcepub unsafe fn new_unchecked(ptr: NonNull<u8>) -> Self
pub unsafe fn new_unchecked(ptr: NonNull<u8>) -> Self
Sourcepub unsafe fn write_unchecked<T>(self, object: T) -> NonNull<T>
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
.
Sourcepub unsafe fn cast<T>(self) -> Slot<'a, T>
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>
impl<'a, T> Slot<'a, T>
Sourcepub fn write(self, object: T) -> &'a mut Opaque<T>
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>
}
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more