pub struct Box<T> where T: ?Sized(_);
Methods
impl<T> Box<T>
fn new(x: T) -> Box<T>
Allocates memory on the heap and then moves x
into it.
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
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.
Consumes the Box
, returning the wrapped raw pointer.
After call to this function, caller is responsible for the memory
previously managed by Box
, in particular caller should properly
destroy T
and release memory. The proper way to do it is to
convert pointer back to Box
with Box::from_raw
function, because
Box
does not specify, how memory is allocated.
let seventeen = Box::new(17u32);
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> 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 FromA: Default + Extend<A>, Self: Iterator<Item=(A, B)>, FromB: Default + Extend<B>
fn cloned<'a, T>(self) -> Cloned<Self> where T: 'a + Clone, Self: Iterator<Item=&'a T>
fn cycle(self) -> Cycle<Self> where Self: Clone
fn sum<S = Self::Item>(self) -> S where S: Add<Self::Item, Output=S> + Zero
fn product<P = Self::Item>(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