Struct collections::boxed::BoxStable
[-] [+]
[src]
pub struct Box<T>(_);
A pointer type for heap allocation.
See the module-level documentation for more.
Methods
impl<T> Box<T>
fn new(x: T) -> Box<T>
Allocates memory on the heap and then moves x
into it.
Examples
fn main() { let x = Box::new(5); }let x = Box::new(5);
impl<T> Box<T> where T: ?Sized
unsafe fn from_raw(raw: *mut T) -> Box<T>
Constructs a box from the raw pointer.
After this function call, pointer is owned by resulting box.
In particular, it means that Box
destructor calls destructor
of T
and releases 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
with
boxed::into_raw
function.
Function is unsafe, because improper use of this function may lead to memory problems like double-free, for example if the function is called twice on the same raw pointer.
impl Box<Any + 'static>
fn downcast<T>(self) -> Result<Box<T>, Box<Any + 'static>> where T: Any
Attempt to downcast the box to a concrete type.
impl Box<Any + 'static + Send>
fn downcast<T>(self) -> Result<Box<T>, Box<Any + 'static + Send>> where T: Any
Attempt to downcast the box to a concrete type.
Trait Implementations
impl<T> Default for Box<T> where T: Default
impl<T> Default for Box<[T]>
impl<T> Clone for Box<T> where T: Clone
fn clone(&self) -> Box<T>
Returns a new box with a clone()
of this box's contents.
Examples
fn main() { let x = Box::new(5); let y = x.clone(); }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
#![feature(alloc, core)] fn main() { let x = Box::new(5); let mut y = Box::new(10); y.clone_from(&x); assert_eq!(*y, 5); }let x = Box::new(5); let mut y = Box::new(10); y.clone_from(&x); assert_eq!(*y, 5);