Struct fallacy_box::Box
source · [−]Expand description
A pointer type for heap allocation.
Implementations
sourceimpl<T> Box<T>
impl<T> Box<T>
sourcepub fn try_new(x: T) -> Result<Self, AllocError>
pub fn try_new(x: T) -> Result<Self, AllocError>
Allocates memory on the heap then places x into it,
returning an error if the allocation fails
This doesn’t actually allocate if T is zero-sized.
sourceimpl<T: ?Sized> Box<T>
impl<T: ?Sized> Box<T>
sourcepub unsafe fn from_raw(raw: *mut T) -> Self
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. For this
to be safe, the memory must have been allocated in accordance
with the [memory layout] used by Box .
Safety
This function is unsafe because improper use may lead to memory problems. For example, a double-free may occur if the function is called twice on the same raw pointer.
sourceimpl<T, A: Allocator> Box<T, A>
impl<T, A: Allocator> Box<T, A>
sourcepub fn try_new_in(x: T, alloc: A) -> Result<Self, AllocError>
pub fn try_new_in(x: T, alloc: A) -> Result<Self, AllocError>
Allocates memory in the given allocator then places x into it,
returning an error if the allocation fails
This doesn’t actually allocate if T is zero-sized.
sourceimpl<T: ?Sized, A: Allocator> Box<T, A>
impl<T: ?Sized, A: Allocator> Box<T, A>
sourcepub unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self
pub unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self
Constructs a box from a raw pointer in the given allocator.
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. For this
to be safe, the memory must have been allocated in accordance
with the [memory layout] used by Box .
Safety
This function is unsafe because improper use may lead to memory problems. For example, a double-free may occur if the function is called twice on the same raw pointer.
sourcepub fn into_raw(b: Self) -> *mut T
pub fn into_raw(b: 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.
sourcepub fn into_raw_with_allocator(b: Self) -> (*mut T, A)
pub fn into_raw_with_allocator(b: Self) -> (*mut T, A)
Consumes the Box, returning a wrapped raw pointer and the allocator.
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.
sourcepub fn allocator(b: &Self) -> &A
pub fn allocator(b: &Self) -> &A
Returns a reference to the underlying allocator.
Note: this is an associated function, which means that you have
to call it as Box::allocator(&b) instead of b.allocator(). This
is so that there is no conflict with a method on the inner type.
sourcepub fn leak<'a>(b: Self) -> &'a mut T where
A: 'a,
pub fn leak<'a>(b: 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.
pub fn into_std(self) -> StdBox<T, A>
pub fn from_std(b: StdBox<T, A>) -> Self
Trait Implementations
sourceimpl<T: Ord + ?Sized, A: Ord + Allocator> Ord for Box<T, A>
impl<T: Ord + ?Sized, A: Ord + Allocator> Ord for Box<T, A>
sourceimpl<T: PartialOrd + ?Sized, A: PartialOrd + Allocator> PartialOrd<Box<T, A>> for Box<T, A>
impl<T: PartialOrd + ?Sized, A: PartialOrd + Allocator> PartialOrd<Box<T, A>> for Box<T, A>
sourcefn partial_cmp(&self, other: &Box<T, A>) -> Option<Ordering>
fn partial_cmp(&self, other: &Box<T, A>) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
sourceimpl<T: TryClone, A: Allocator + TryClone> TryClone for Box<T, A>
impl<T: TryClone, A: Allocator + TryClone> TryClone for Box<T, A>
fn try_clone(&self) -> Result<Self, AllocError>
sourcefn try_clone_from(&mut self, source: &Self) -> Result<(), AllocError>
fn try_clone_from(&mut self, source: &Self) -> Result<(), AllocError>
Performs copy-assignment from source. Read more
impl<T: Eq + ?Sized, A: Eq + Allocator> Eq for Box<T, A>
impl<T: ?Sized, A: Allocator> StructuralEq for Box<T, A>
impl<T: ?Sized, A: Allocator> StructuralPartialEq for Box<T, A>
Auto Trait Implementations
impl<T: ?Sized, A> RefUnwindSafe for Box<T, A> where
A: RefUnwindSafe,
T: RefUnwindSafe,
impl<T: ?Sized, A> Send for Box<T, A> where
A: Send,
T: Send,
impl<T: ?Sized, A> Sync for Box<T, A> where
A: Sync,
T: Sync,
impl<T: ?Sized, A> Unpin for Box<T, A>
impl<T: ?Sized, A> UnwindSafe for Box<T, A> where
A: UnwindSafe,
T: 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