Struct alloc::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

let x = Box::new(5);

impl<T: ?Sized> Box<T>

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, so the only valid pointer to pass to this function is the one taken from another Box with box::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.

Trait Implementations

impl<T: Default> Default for Box<T>

fn default() -> Box<T>

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

fn default() -> 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);

impl<T: ?Sized + PartialEq> PartialEq for Box<T>

fn eq(&self, other: &Box<T>) -> bool

fn ne(&self, other: &Box<T>) -> bool

impl<T: ?Sized + PartialOrd> PartialOrd for Box<T>

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

fn lt(&self, other: &Box<T>) -> bool

fn le(&self, other: &Box<T>) -> bool

fn ge(&self, other: &Box<T>) -> bool

fn gt(&self, other: &Box<T>) -> bool

impl<T: ?Sized + Ord> Ord for Box<T>

fn cmp(&self, other: &Box<T>) -> Ordering

impl<T: ?Sized + Eq> Eq for Box<T>

fn assert_receiver_is_total_eq(&self)

impl<T: ?Sized + Hash> Hash for Box<T>

fn hash<H: Hasher>(&self, state: &mut H)

fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher

impl BoxAny for Box<Any>

fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>>

impl<T: Display + ?Sized> Display for Box<T>

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

impl<T: Debug + ?Sized> Debug for Box<T>

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

impl Debug for Box<Any>

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

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

type Target = T

fn deref(&self) -> &T

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

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

impl<I: Iterator + ?Sized> Iterator for Box<I>

type Item = Item

fn next(&mut self) -> Option<Item>

fn size_hint(&self) -> (usize, Option<usize>)

impl<I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for Box<I>

fn next_back(&mut self) -> Option<Item>

impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I>

fn len(&self) -> usize

impl<'a, E: Error + 'a> FromError<E> for Box<Error + 'a>

fn from_error(err: E) -> Box<Error + 'a>