pub struct BrandedBlock<'brand, T>where
T: ?Sized,{ /* private fields */ }Expand description
A wrapper representing a heap block branded with a compile-time unique lifetime.
Implementations§
Source§impl<'brand, T> BrandedBlock<'brand, T>where
T: ?Sized,
impl<'brand, T> BrandedBlock<'brand, T>where
T: ?Sized,
Source§impl<'brand, T> BrandedBlock<'brand, T>
impl<'brand, T> BrandedBlock<'brand, T>
Sourcepub unsafe fn cast<U>(self) -> BrandedBlock<'brand, U>
pub unsafe fn cast<U>(self) -> BrandedBlock<'brand, U>
Casts this branded block to managed memory of a different type, preserving the brand.
§Safety
The returned BrandedBlock<'brand, U> is trusted by safe APIs that
interpret the pointee as a U: crate::Heap::free runs
core::ptr::drop_in_place::<U> on it and derives its deallocation
path from size_of_val of the U, crate::Heap::realloc reads
the pointee’s layout the same way, and
super::BrandedCell::from_block hands out &U/&mut U. The caller must
therefore guarantee:
- Layout: the block’s allocation is at least
size_of::<U>()bytes and aligned toalign_of::<U>()(e.g. it was allocated for a layout that coversU), and - Initialization/drop discipline: either the memory holds a valid
Ubefore any path reads or drops it as one, or the block is treated as uninitializedUstorage — written with a validUbefore such a path (ascrate::Heap::alloc_initdoes), or released exclusively through the non-droppingcrate::Heap::free_uninit.
Violating either (for example casting an initialized usize block to
String and freeing it) is a transmute-and-drop and undefined
behavior.
Trait Implementations§
Source§impl<'brand, T> Debug for BrandedBlock<'brand, T>where
T: ?Sized,
impl<'brand, T> Debug for BrandedBlock<'brand, T>where
T: ?Sized,
impl<'brand, T> Eq for BrandedBlock<'brand, T>where
T: ?Sized,
Source§impl<'brand, T> Hash for BrandedBlock<'brand, T>where
T: ?Sized,
impl<'brand, T> Hash for BrandedBlock<'brand, T>where
T: ?Sized,
Source§impl<'brand, T> Ord for BrandedBlock<'brand, T>where
T: ?Sized,
impl<'brand, T> Ord for BrandedBlock<'brand, T>where
T: ?Sized,
Source§fn cmp(&self, other: &BrandedBlock<'brand, T>) -> Ordering
fn cmp(&self, other: &BrandedBlock<'brand, T>) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl<'brand, T> PartialEq for BrandedBlock<'brand, T>where
T: ?Sized,
impl<'brand, T> PartialEq for BrandedBlock<'brand, T>where
T: ?Sized,
Source§impl<'brand, T> PartialOrd for BrandedBlock<'brand, T>where
T: ?Sized,
impl<'brand, T> PartialOrd for BrandedBlock<'brand, T>where
T: ?Sized,
Auto Trait Implementations§
impl<'brand, T> !Send for BrandedBlock<'brand, T>
impl<'brand, T> !Sync for BrandedBlock<'brand, T>
impl<'brand, T> Freeze for BrandedBlock<'brand, T>
impl<'brand, T> RefUnwindSafe for BrandedBlock<'brand, T>
impl<'brand, T> Unpin for BrandedBlock<'brand, T>
impl<'brand, T> UnsafeUnpin for BrandedBlock<'brand, T>
impl<'brand, T> UnwindSafe for BrandedBlock<'brand, 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