flex_alloc::boxed

Struct Box

Source
pub struct Box<T: ?Sized, A: Allocator = Global> { /* private fields */ }
Expand description

A pointer type that uniquely owns an allocation of type T.

Implementations§

Source§

impl<T, A: AllocatorDefault> Box<T, A>

Source

pub fn new(value: T) -> Box<T, A>

Allocates in the associated allocator and then places value into it. This doesn’t actually allocate if T is zero-sized.

Source

pub fn new_uninit() -> Box<MaybeUninit<T>, A>

Allocates uninitialized memory in the associated allocator. This doesn’t actually allocate if T is zero-sized.

Source

pub fn try_new(value: T) -> Result<Box<T, A>, StorageError>

Tries to allocate in the associated allocator and then places value into it. This doesn’t actually allocate if T is zero-sized.

Source

pub fn try_new_uninit() -> Result<Box<MaybeUninit<T>, A>, StorageError>

Tries to allocate uninitialized memory in the associated allocator. This doesn’t actually allocate if T is zero-sized.

Source

pub fn into_inner(boxed: Self) -> T

Unwraps this Box into its contained value.

Source§

impl<T, A: AllocatorDefault> Box<[T], A>

Source

pub fn new_uninit_slice(len: usize) -> Box<[MaybeUninit<T>], A>

Allocate uninitialized memory in the associated allocator. This doesn’t actually allocate if T is zero-sized.

Source

pub fn try_new_uninit_slice( len: usize, ) -> Result<Box<[MaybeUninit<T>], A>, StorageError>

Tries to allocate uninitialized memory in the associated allocator. This doesn’t actually allocate if T is zero-sized.

Source§

impl<T: ?Sized, A: AllocatorDefault> Box<T, A>

Source

pub unsafe fn from_raw(raw: *mut T) -> Self

Constructs a box from a raw pointer.

After calling this function, the raw pointer is owned by the resulting Box. Specifically, the box destructor will call the destructor of T and free the allocated memory.

§Safety

The memory must have been allocated in accordance with the memory layout used by Box.

Source

pub fn into_raw(boxed: Self) -> *mut T

Consumes the Box, returning a wrapped raw pointer.

The pointer will be properly aligned and non-null.

After calling this function, the caller is responsible for the memory previously managed by the Box. In particular, the caller should properly destroy T and release the memory, taking into account the memory layout used by Box. The easiest way to do this is to convert the raw pointer back into a Box with the Box::from_raw function, allowing the Box destructor to perform the cleanup.

Note: this is an associated function, which means that you have to call it as Box::into_raw(b) instead of b.into_raw(). This is so that there is no conflict with a method on the inner type.

Source§

impl<T, A: Allocator> Box<T, A>

Source

pub fn new_in<I>(value: T, alloc_in: I) -> Box<T, A>
where I: AllocateIn<Alloc = A>,

Allocates in the associated allocation target and then places value into it. This doesn’t actually allocate if T is zero-sized.

Source

pub fn new_uninit_in<I>(alloc_in: I) -> Box<MaybeUninit<T>, A>
where I: AllocateIn<Alloc = A>,

Allocates uninitialized memory in the associated allocation target. This doesn’t actually allocate if T is zero-sized.

Source

pub fn try_new_in<I>(value: T, alloc_in: I) -> Result<Box<T, A>, StorageError>
where I: AllocateIn<Alloc = A>,

Tries to allocate in the associated allocation target and then places value into it. This doesn’t actually allocate if T is zero-sized.

Source

pub fn try_new_uninit_in<I>( alloc_in: I, ) -> Result<Box<MaybeUninit<T>, A>, StorageError>
where I: AllocateIn<Alloc = A>,

Tries to allocate uninitialized memory in the associated allocation target. This doesn’t actually allocate if T is zero-sized.

Source§

impl<T, A: Allocator> Box<[T], A>

Source

pub fn new_uninit_slice_in<I>( len: usize, alloc_in: I, ) -> Box<[MaybeUninit<T>], A>
where I: AllocateIn<Alloc = A>,

Allocates uninitialized memory in the associated allocation target. This doesn’t actually allocate if T is zero-sized.

Source

pub fn try_new_uninit_slice_in<I>( len: usize, alloc_in: I, ) -> Result<Box<[MaybeUninit<T>], A>, StorageError>
where I: AllocateIn<Alloc = A>,

Tries to allocates uninitialized memory in the associated allocation target. This doesn’t actually allocate if T is zero-sized.

Source

pub fn into_vec(self) -> Vec<T, A>

Convert this boxed slice into a Vec<T, A> without reallocating.

Source§

impl<A: Allocator> Box<str, A>

Source

pub fn from_utf8(boxed: Box<[u8], A>) -> Result<Self, Utf8Error>

Convert a boxed slice of bytes into a Box<str>.

If you are sure that the byte slice is valid UTF-8, and you don’t want to incur the overhead of the validity check, there is an unsafe version of this function, Box::from_utf8_unchecked, which has the same behavior but skips the check.

Source

pub unsafe fn from_utf8_unchecked(boxed: Box<[u8], A>) -> Self

Convert a boxed slice of bytes into a Box<str>.

§Safety

The contained bytes must be valid UTF-8.

Source§

impl<T: Clone, A: AllocatorDefault> Box<[T], A>

Source

pub fn from_slice(data: &[T]) -> Self

Create a boxed slice by cloning a slice reference.

Source

pub fn try_from_slice(data: &[T]) -> Result<Self, StorageError>

Try to create a boxed slice by cloning a slice reference.

Source§

impl<T: Clone, A: Allocator> Box<[T], A>

Source

pub fn from_slice_in<I>(data: &[T], alloc_in: I) -> Self
where I: AllocateIn<Alloc = A>,

Create a boxed slice directly in an allocation target by cloning a slice reference.

Source

pub fn try_from_slice_in<I>( data: &[T], alloc_in: I, ) -> Result<Self, StorageError>
where I: AllocateIn<Alloc = A>,

Try to create a boxed slice directly in an allocation target by cloning a slice reference.

Source§

impl<T: ?Sized, A: Allocator> Box<T, A>

Source

pub fn allocator(&self) -> &A

Obtain a reference to the contained allocator instance.

Source

pub fn as_ptr(&self) -> *const T

Get a read pointer to the beginning of the data allocation. This may be a dangling pointer if T is zero sized or the current capacity is zero.

Source

pub fn as_mut_ptr(&mut self) -> *mut T

Get a mutable pointer to the beginning of the data allocation. This may be a dangling pointer if T is zero sized or the current capacity is zero.

Source

pub unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self

Constructs a box from a raw pointer and an allocator instance.

After calling this function, the raw pointer is owned by the resulting Box. Specifically, the box destructor will call the destructor of T and free the allocated memory.

§Safety

The memory must have been allocated in accordance with the memory layout used by Box.

Source

pub fn into_raw_with_allocator(boxed: Self) -> (*mut T, A)

Consumes the Box, returning a wrapped raw pointer and an allocator instance.

The pointer will be properly aligned and non-null.

After calling this function, the caller is responsible for the memory previously managed by the Box. In particular, the caller should properly destroy T and release the memory, taking into account the memory layout used by Box. The easiest way to do this is to convert the raw pointer back into a Box with the Box::from_raw_in function, allowing the Box destructor to perform the cleanup.

Note: this is an associated function, which means that you have to call it as Box::into_raw_with_allocator(b) instead of b.into_raw_with_allocator(). This is so that there is no conflict with a method on the inner type.

Source

pub fn leak<'a>(boxed: Self) -> &'a mut T
where A: 'a,

Consumes and leaks the Box, returning a mutable reference, &'a mut T.

Note that the type T must outlive the chosen lifetime 'a. If the type has only static references, or none at all, then this may be chosen to be 'static.

This function is mainly useful for data that lives for the remainder of the program’s life. Dropping the returned reference will cause a memory leak. If this is not acceptable, the reference should first be wrapped with the Box::from_raw function producing a Box. This Box can then be dropped which will properly destroy T and release the allocated memory.

Note: this is an associated function, which means that you have to call it as Box::leak(b) instead of b.leak(). This is so that there is no conflict with a method on the inner type.

Source§

impl<T, A: Allocator> Box<MaybeUninit<T>, A>

Source

pub unsafe fn assume_init(self) -> Box<T, A>

Converts to Box<T, A>.

§Safety

The contents of the box must be initialized prior to calling, or else undefined behavior may result from the use of uninitialized memory.

Source

pub fn write(boxed: Self, value: T) -> Box<T, A>

Writes the value and converts to Box<T, A>.

This method converts the box similarly to Box::assume_init but writes value into it before conversion, thus guaranteeing safety. In some scenarios use of this method may improve performance because the compiler may be able to optimize copying from stack.

Source§

impl<T, A: Allocator> Box<[MaybeUninit<T>], A>

Source

pub unsafe fn assume_init(self) -> Box<[T], A>

Converts to Box<[T], A>.

§Safety

The contents of the box must be initialized prior to calling, or else undefined behavior may result from the use of uninitialized memory.

Source§

impl<T, A: Allocator, const N: usize> Box<[T; N], A>

Source

pub fn into_boxed_slice(boxed: Self) -> Box<[T], A>

Converts a Box<T, A> into a Box<[T], A>.

This conversion does not allocate on the heap and happens in place.

Trait Implementations§

Source§

impl<T: ?Sized, A: Allocator> AsMut<T> for Box<T, A>

Source§

fn as_mut(&mut self) -> &mut T

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T: ?Sized, A: Allocator> AsRef<T> for Box<T, A>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: ?Sized, A: Allocator> Borrow<T> for Box<T, A>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T: ?Sized, A: Allocator> BorrowMut<T> for Box<T, A>

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T: Clone, A: Allocator + Clone> Clone for Box<[T], A>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: Allocator + Clone> Clone for Box<str, A>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: ?Sized> ConvertAlloc<Box<T>> for Box<T>

Source§

fn convert(self) -> Box<T, Global>

Convert directly into the target type, ideally without reallocating.
Source§

impl<T: ?Sized> ConvertAlloc<Box<T>> for Box<T, Global>

Source§

fn convert(self) -> Box<T>

Convert directly into the target type, ideally without reallocating.
Source§

impl<T: ?Sized + Debug, A: Allocator> Debug for Box<T, A>

Source§

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

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

impl<T, A: AllocatorDefault> Default for Box<[T], A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Default, A: AllocatorDefault> Default for Box<T, A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<A: AllocatorDefault> Default for Box<str, A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: ?Sized, A: Allocator> Deref for Box<T, A>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: ?Sized, A: Allocator> DerefMut for Box<T, A>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T: ?Sized, A: Allocator> Drop for Box<T, A>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Clone, A: AllocatorDefault> From<&[T]> for Box<[T], A>

Source§

fn from(data: &[T]) -> Self

Converts to this type from the input type.
Source§

impl<A: AllocatorDefault> From<&str> for Box<str, A>

Source§

fn from(data: &str) -> Self

Converts to this type from the input type.
Source§

impl<T, A: AllocatorDefault, const N: usize> From<[T; N]> for Box<[T], A>

Source§

fn from(data: [T; N]) -> Self

Converts to this type from the input type.
Source§

impl<T, C> From<Box<[T], <C as VecConfigAlloc<T>>::Alloc>> for Vec<T, C>
where C: VecConfigAlloc<T>,

Source§

fn from(boxed: Box<[T], C::Alloc>) -> Self

Converts to this type from the input type.
Source§

impl<T, C, const N: usize> From<Box<[T; N], <C as VecConfigAlloc<T>>::Alloc>> for Vec<T, C>
where C: VecConfigAlloc<T>,

Source§

fn from(boxed: Box<[T; N], C::Alloc>) -> Self

Converts to this type from the input type.
Source§

impl<T, A: AllocatorDefault> From<T> for Box<T, A>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T, C> From<Vec<T, C>> for Box<[T], C::Alloc>
where C: VecConfigAlloc<T>,

Source§

fn from(vec: Vec<T, C>) -> Self

Converts to this type from the input type.
Source§

impl<T, A: AllocatorDefault> FromIterator<T> for Box<[T], A>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T: ?Sized + Ord, A: Allocator> Ord for Box<T, A>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

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

impl<T: ?Sized + PartialEq, A: Allocator> PartialEq for Box<T, A>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Box<T, A>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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<T, A: Allocator, const N: usize> TryFrom<Box<[T], A>> for Box<[T; N], A>

Source§

type Error = Box<[T], A>

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

fn try_from(boxed: Box<[T], A>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T, A: Allocator, const N: usize> TryFrom<Vec<T, A>> for Box<[T; N], A>

Source§

type Error = Vec<T, A>

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

fn try_from(vec: Vec<T, A>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: ?Sized + Zeroize, A: Allocator> Zeroize for Box<T, A>

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl<T: ?Sized + Eq, A: Allocator> Eq for Box<T, A>

Source§

impl<T: Send + ?Sized, A: Allocator + Send> Send for Box<T, A>

Source§

impl<T: Sync + ?Sized, A: Allocator + Sync> Sync for Box<T, A>

Source§

impl<T: ?Sized, A: Allocator> Unpin for Box<T, A>

Source§

impl<T: ?Sized, A: AllocatorZeroizes> ZeroizeOnDrop for Box<T, A>

Auto Trait Implementations§

§

impl<T, A> Freeze for Box<T, A>
where A: Freeze, T: ?Sized,

§

impl<T, A> RefUnwindSafe for Box<T, A>

§

impl<T, A> UnwindSafe for Box<T, A>
where A: UnwindSafe, T: RefUnwindSafe + ?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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, A> ToOwnedIn<A> for T
where T: Clone + 'static, A: Allocator,

Source§

type Owned = T

The owned representation of this type.
Source§

fn try_to_owned_in<I>( &self, _alloc_in: I, ) -> Result<<T as ToOwnedIn<A>>::Owned, StorageError>
where I: AllocateIn<Alloc = A>,

To to create an owned copy of this instance in a given allocation target.
Source§

fn to_owned_in<I>(&self, alloc_in: I) -> Self::Owned
where I: AllocateIn<Alloc = A>,

Create an owned copy of this instance in a given allocation target.
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.