Struct Box

Source
pub struct Box<T: ?Sized> { /* private fields */ }
Expand description

A heap-allocated memory block.

Implementations§

Source§

impl<T> Box<[T]>

Source

pub fn new_slice_zeroed(len: usize) -> Result<Self, KernelError>

Create a new zeroed heap-allocated slice with the given length.

len - The length of the slice.

Returns a new heap-allocated slice with the given length or an error if the allocation failed.

Source

pub const fn new_slice_empty() -> Self

Create a new empty slice.

Returns a new empty slice.

Source

pub fn new_slice_uninit( len: usize, ) -> Result<Box<[MaybeUninit<T>]>, KernelError>

Create a new uninit heap-allocated slice with the given length.

len - The length of the slice.

Returns a new heap-allocated slice with the given length or an error if the allocation failed.

Source§

impl<T> Box<T>

Source

pub fn new(value: T) -> Option<Self>

Create a new heap-allocated value.

value - The value to store on the heap.

Returns a new heap-allocated value or None if the allocation failed.

Source

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

Returns a mutable reference to the heap-allocated value.

Source

pub fn as_ref(&self) -> &T

Returns an immutable reference to the heap-allocated value.

Source

pub fn into_raw(self) -> NonNull<T>

Consumes the Box, returning a pointer to the heap-allocated value.

The caller is responsible for freeing the memory with the global free function. A pointer created with this function can be converted back into a Box with the from_raw function.

Source

pub unsafe fn from_raw(ptr: NonNull<T>) -> Self

Moves a pointer to a heap-allocated value into a Box.

ptr - The pointer to the heap-allocated value.

Returns a new Box managing the given pointer.

§Safety

The caller must ensure that the pointer is valid and that the memory is not freed while the Box is alive.

The caller must ensure that the following conditions are met:

  • The pointer must be allocated with the global malloc function.
  • The pointer must be unique and not aliased.
  • The pointer must be properly aligned.
  • The pointer must point to a valid T.

The Box takes ownership of the memory and will free it with the global allocator when dropped.

Trait Implementations§

Source§

impl<T> AsMut<T> for Box<T>

Source§

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

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

impl<T> AsRef<T> for Box<T>

Source§

fn as_ref(&self) -> &T

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

impl<T> Deref for Box<[T]>

Source§

type Target = [T]

The resulting type after dereferencing.
Source§

fn deref(&self) -> &[T]

Dereferences the value.
Source§

impl<T> Deref for Box<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T> DerefMut for Box<[T]>

Source§

fn deref_mut(&mut self) -> &mut [T]

Mutably dereferences the value.
Source§

impl<T> DerefMut for Box<T>

Source§

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

Mutably dereferences the value.
Source§

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

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> Index<Range<usize>> for Box<[T]>

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: Range<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> Index<RangeFrom<usize>> for Box<[T]>

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: RangeFrom<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> Index<RangeTo<usize>> for Box<[T]>

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: RangeTo<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> Index<usize> for Box<[T]>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<Range<usize>> for Box<[T]>

Source§

fn index_mut(&mut self, index: Range<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<RangeFrom<usize>> for Box<[T]>

Source§

fn index_mut(&mut self, index: RangeFrom<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<RangeTo<usize>> for Box<[T]>

Source§

fn index_mut(&mut self, index: RangeTo<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<usize> for Box<[T]>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

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

§

impl<T> RefUnwindSafe for Box<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> !Send for Box<T>

§

impl<T> !Sync for Box<T>

§

impl<T> Unpin for Box<T>
where T: ?Sized,

§

impl<T> UnwindSafe for Box<T>
where 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> 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, 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.