Struct alloc::boxed::Box
[−]
[src]
pub struct Box<T: ?Sized>(_);1.0.0
A pointer type for heap allocation.
See the module-level documentation for more.
Methods
impl<T> Box<T>
impl<T: ?Sized> Box<T>
unsafe fn from_raw(raw: *mut T) -> Self
1.4.0
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. Since the
way Box
allocates and releases memory is unspecified, the
only valid pointer to pass to this function is the one taken
from another Box
via the Box::into_raw
function.
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.
fn into_raw(b: Box<T>) -> *mut T
1.4.0
Consumes the Box
, returning the wrapped raw pointer.
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. The
proper way to do so is to convert the raw pointer back into a
Box
with the Box::from_raw
function.
Examples
let seventeen = Box::new(17); let raw = Box::into_raw(seventeen); let boxed_again = unsafe { Box::from_raw(raw) };
impl Box<Any>
fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>>
Attempt to downcast the box to a concrete type.
impl Box<Any + Send>
fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any + Send>>
Attempt to downcast the box to a concrete type.
Trait Implementations
impl<T> Boxed for Box<T>
type Data = T
placement_new_protocol
#27779)type Place = IntermediateBox<T>
placement_new_protocol
#27779)unsafe fn finalize(b: IntermediateBox<T>) -> Box<T>
placement_new_protocol
#27779)impl<T: Default> Default for Box<T>
impl<T> Default for Box<[T]>
impl<T: Clone> Clone for Box<T>
fn clone(&self) -> Box<T>
Returns a new box with a clone()
of this box's contents.
Examples
let x = Box::new(5); let y = x.clone();
fn clone_from(&mut self, source: &Box<T>)
Copies source
's contents into self
without creating a new allocation.
Examples
let x = Box::new(5); let mut y = Box::new(10); y.clone_from(&x); assert_eq!(*y, 5);