Struct storage_api::RawBox
source · [−]Expand description
A raw box around some storage. Bundles the storage and its handle.
Implementations
sourceimpl<T: ?Sized, S: Storage> RawBox<T, S>
impl<T: ?Sized, S: Storage> RawBox<T, S>
sourcepub unsafe fn new(
metadata: <T as Pointee>::Metadata,
storage: S
) -> Result<Self, S>
pub unsafe fn new(
metadata: <T as Pointee>::Metadata,
storage: S
) -> Result<Self, S>
Create a new box for the object described by the given metadata.
The object is not initialized.
(Do we want a new_zeroed
?)
Safety
- The metadata must describe a layout valid for a rust object.
- This requirement exists due to the safety requirements of
size_of_val_raw
andalign_of_val_raw
. I think we definitely want a way to go compute layout from type and metadata safely, with a check that it produces a valid layout. - On each unsized kind, this would imply:
- slices: size computation uses saturating/checked multiplication.
- traits: vtable must always be valid (as a safety invariant).
- composites: size computation uses saturating/checked addition.
- externs: any valid metadata must compute valid size/align or indicates that size/align is unknown and/or needs a valid object.
- rust-lang/rust#95832 is an attempt to quantize how expensive it would be to make slice size computation always use saturating math.
- This requirement exists due to the safety requirements of
sourcepub fn as_ref(&self) -> &MaybeUninit<T> where
T: Sized,
pub fn as_ref(&self) -> &MaybeUninit<T> where
T: Sized,
Get a reference to the boxed object.
sourcepub fn as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
Get a pointer valid for reads only to the boxed object.
The pointer is invalidated when the box is moved or used by mutable reference.
sourcepub fn as_mut(&mut self) -> &mut MaybeUninit<T> where
T: Sized,
pub fn as_mut(&mut self) -> &mut MaybeUninit<T> where
T: Sized,
Get a mutable reference to the boxed object.
sourcepub fn as_mut_ptr(&mut self) -> *mut T
pub fn as_mut_ptr(&mut self) -> *mut T
Get a pointer valid for reads and writes to the boxed object.
The pointer is invalidated when the box is moved or used by reference.
sourcepub fn into_raw_parts(self) -> (S::Handle, <T as Pointee>::Metadata, S)
pub fn into_raw_parts(self) -> (S::Handle, <T as Pointee>::Metadata, S)
Break a raw box into its component parts.
sourcepub unsafe fn from_raw_parts(
handle: S::Handle,
metadata: <T as Pointee>::Metadata,
storage: S
) -> Self
pub unsafe fn from_raw_parts(
handle: S::Handle,
metadata: <T as Pointee>::Metadata,
storage: S
) -> Self
Reassemble a raw box from its component parts.
Trait Implementations
Auto Trait Implementations
impl<T: ?Sized, S> RefUnwindSafe for RawBox<T, S> where
S: RefUnwindSafe,
<S as Storage>::Handle: RefUnwindSafe,
<T as Pointee>::Metadata: RefUnwindSafe,
impl<T: ?Sized, S> Send for RawBox<T, S> where
S: Send,
impl<T: ?Sized, S> Sync for RawBox<T, S> where
S: Sync,
impl<T: ?Sized, S> Unpin for RawBox<T, S> where
S: Unpin,
impl<T: ?Sized, S> UnwindSafe for RawBox<T, S> where
S: UnwindSafe,
<S as Storage>::Handle: UnwindSafe,
<T as Pointee>::Metadata: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more