pub struct Box<T> where T: ?Sized(Unique<T>);
Methods
impl<T> Box<T>
fn new(x: T) -> Box<T>
Allocates memory on the heap and then places x
into it.
let five = Box::new(5);
impl<T> Box<T> where T: ?Sized
unsafe fn from_raw(raw: *mut T) -> Box<T>
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.
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.
let seventeen = Box::new(17);
let raw = Box::into_raw(seventeen);
let boxed_again = unsafe { Box::from_raw(raw) };
impl Box<Any + 'static>
Attempt to downcast the box to a concrete type.
Attempt to downcast the box to a concrete type.
Trait Implementations
fn eq(&self, other: &Box<T>) -> bool
fn ne(&self, other: &Box<T>) -> bool
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> Ord for Box<T> where T: Ord + ?Sized
impl<T> Eq for Box<T> where T: Eq + ?Sized
impl<T> From<T> for Box<T>
impl<T> Deref for Box<T> where T: ?Sized
type Target = T
fn deref(&self) -> &T
type Item = I::Item
fn count(self) -> usize
fn nth(&mut self, n: usize) -> Option<Self::Item>
fn map<B, F>(self, f: F) -> Map<Self, F> where F: FnMut(Self::Item) -> B
fn filter<P>(self, predicate: P) -> Filter<Self, P> where P: FnMut(&Self::Item) -> bool
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where P: FnMut(&Self::Item) -> bool
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where P: FnMut(&Self::Item) -> bool
fn skip(self, n: usize) -> Skip<Self>
fn take(self, n: usize) -> Take<Self>
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F> where F: FnMut(&mut St, Self::Item) -> Option<B>
fn fuse(self) -> Fuse<Self>
fn inspect<F>(self, f: F) -> Inspect<Self, F> where F: FnMut(&Self::Item) -> ()
fn by_ref(&mut self) -> &mut Self
fn partition<B, F>(self, f: F) -> (B, B) where B: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> bool
fn fold<B, F>(self, init: B, f: F) -> B where F: FnMut(B, Self::Item) -> B
fn all<F>(&mut self, f: F) -> bool where F: FnMut(Self::Item) -> bool
fn any<F>(&mut self, f: F) -> bool where F: FnMut(Self::Item) -> bool
fn find<P>(&mut self, predicate: P) -> Option<Self::Item> where P: FnMut(&Self::Item) -> bool
fn position<P>(&mut self, predicate: P) -> Option<usize> where P: FnMut(Self::Item) -> bool
fn max_by<B, F>(self, f: F) -> Option<Self::Item> where B: Ord, F: FnMut(&Self::Item) -> B
fn min_by<B, F>(self, f: F) -> Option<Self::Item> where F: FnMut(&Self::Item) -> B, B: Ord
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB) where Self: Iterator<Item=(A, B)>, FromA: Default + Extend<A>, FromB: Default + Extend<B>
fn cloned<'a, T>(self) -> Cloned<Self> where Self: Iterator<Item=&'a T>, T: 'a + Clone
fn cycle(self) -> Cycle<Self> where Self: Clone
fn sum<S>(self) -> S where S: Add<Self::Item, Output=S> + Zero
fn product<P>(self) -> P where P: Mul<Self::Item, Output=P> + One
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output=R> + 'a>
type Output = R
extern "rust-call" fn call_once(self, args: A) -> R
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output=R> + 'a + Send>
type Output = R
extern "rust-call" fn call_once(self, args: A) -> R
impl<T> Clone for Box<[T]> where T: Clone
impl<T> Borrow<T> for Box<T> where T: ?Sized
impl<T> AsRef<T> for Box<T> where T: ?Sized
impl<T> AsMut<T> for Box<T> where T: ?Sized
fn as_mut(&mut self) -> &mut T