Skip to main content

BrandedBox

Struct BrandedBox 

Source
pub struct BrandedBox<'brand, 'heap, T, P = StandardPolicy, B = MemoryBackendWrapper>{ /* private fields */ }
Expand description

A uniquely owned, safe pointer to heap-allocated memory of type T from a Heap.

Automatically drops T and deallocates the memory back to the heap on drop.

Implementations§

Source§

impl<'brand, 'heap, T, P, B> BrandedBox<'brand, 'heap, T, P, B>

Source

pub fn new<Permit>( heap: &'heap Heap<'brand, P, B>, permit: Permit, val: T, ) -> Option<BrandedBox<'brand, 'heap, T, P, B>>
where Permit: ReadPermit<'brand>,

Creates a new BrandedBox containing val allocated from the given Heap.

Source§

impl<'brand, 'heap, T, P, B> BrandedBox<'brand, 'heap, T, P, B>

Source

pub fn into_raw(self) -> BrandedBlock<'brand, T>

Consumes the BrandedBox, returning the wrapped raw block without dropping or deallocating.

Source

pub fn into_cell(self) -> BrandedCell<'brand, T>

Converts this BrandedBox into a shared BrandedCell.

The memory remains allocated until it is manually reclaimed.

Source

pub unsafe fn from_cell( heap: &'heap Heap<'brand, P, B>, cell: BrandedCell<'brand, T>, ) -> BrandedBox<'brand, 'heap, T, P, B>

Reconstructs a BrandedBox from a shared BrandedCell.

§Safety

The caller must ensure that no other copies of this BrandedCell (or pointers derived from it) are active or will be used.

Source

pub unsafe fn from_raw( heap: &'heap Heap<'brand, P, B>, block: BrandedBlock<'brand, T>, ) -> BrandedBox<'brand, 'heap, T, P, B>

Reconstructs a BrandedBox from a raw block.

§Safety

The memory block must be initialized with a valid value of type T.

Source§

impl<'brand, 'heap, T, P, B> BrandedBox<'brand, 'heap, T, P, B>

Source

pub fn clone_in<Permit>( &self, permit: &Permit, ) -> Option<BrandedBox<'brand, 'heap, T, P, B>>
where &'token Permit: for<'token> ReadPermit<'brand>,

Clones the box using the given allocator read permit.

Returns None if allocation fails.

Trait Implementations§

Source§

impl<'brand, 'heap, T, P, B> Debug for BrandedBox<'brand, 'heap, T, P, B>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'brand, 'heap, T, P, B> Deref for BrandedBox<'brand, 'heap, T, P, B>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<BrandedBox<'brand, 'heap, T, P, B> as Deref>::Target

Dereferences the value.
Source§

impl<'brand, 'heap, T, P, B> DerefMut for BrandedBox<'brand, 'heap, T, P, B>

Source§

fn deref_mut( &mut self, ) -> &mut <BrandedBox<'brand, 'heap, T, P, B> as Deref>::Target

Mutably dereferences the value.
Source§

impl<'brand, 'heap, T, P, B> Display for BrandedBox<'brand, 'heap, T, P, B>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'brand, 'heap, T, P, B> Drop for BrandedBox<'brand, 'heap, T, P, B>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'brand, 'heap, T, P, B> Eq for BrandedBox<'brand, 'heap, T, P, B>

Source§

impl<'brand, 'heap, T, P, B> Hash for BrandedBox<'brand, 'heap, T, P, B>

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'brand, 'heap, T, P, B> Ord for BrandedBox<'brand, 'heap, T, P, B>

Source§

fn cmp(&self, other: &BrandedBox<'brand, 'heap, T, P, B>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<'brand, 'heap, T, P, B> PartialEq for BrandedBox<'brand, 'heap, T, P, B>

Source§

fn eq(&self, other: &BrandedBox<'brand, 'heap, T, P, B>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'brand, 'heap, T, P, B> PartialOrd for BrandedBox<'brand, 'heap, T, P, B>

Source§

fn partial_cmp( &self, other: &BrandedBox<'brand, 'heap, T, P, B>, ) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'brand, 'heap, T, P, B> Pointer for BrandedBox<'brand, 'heap, T, P, B>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'brand, 'heap, T, P = StandardPolicy, B = MemoryBackendWrapper> !RefUnwindSafe for BrandedBox<'brand, 'heap, T, P, B>

§

impl<'brand, 'heap, T, P = StandardPolicy, B = MemoryBackendWrapper> !Send for BrandedBox<'brand, 'heap, T, P, B>

§

impl<'brand, 'heap, T, P = StandardPolicy, B = MemoryBackendWrapper> !Sync for BrandedBox<'brand, 'heap, T, P, B>

§

impl<'brand, 'heap, T, P = StandardPolicy, B = MemoryBackendWrapper> !UnwindSafe for BrandedBox<'brand, 'heap, T, P, B>

§

impl<'brand, 'heap, T, P, B> Freeze for BrandedBox<'brand, 'heap, T, P, B>
where NonNull<T>: Freeze, &'heap Heap<'brand, P, B>: Freeze, T: ?Sized,

§

impl<'brand, 'heap, T, P, B> Unpin for BrandedBox<'brand, 'heap, T, P, B>
where NonNull<T>: Unpin, &'heap Heap<'brand, P, B>: Unpin, T: ?Sized,

§

impl<'brand, 'heap, T, P, B> UnsafeUnpin for BrandedBox<'brand, 'heap, T, P, B>
where NonNull<T>: UnsafeUnpin, &'heap Heap<'brand, P, B>: UnsafeUnpin, T: ?Sized,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.