Struct drone_core::prelude::Box 1.0.0
[−]
[src]
#[lang = "owned_box"]pub struct Box<T>(_)
where
T: ?Sized;
A pointer type for heap allocation.
See the module-level documentation for more.
Methods
impl<T> Box<T>
[src]
fn new(x: T) -> Box<T>
[src]
Allocates memory on the heap and then places x
into it.
This doesn't actually allocate if T
is zero-sized.
Examples
let five = Box::new(5);
impl<T> Box<T> where
T: ?Sized,
[src]
T: ?Sized,
unsafe fn from_raw(raw: *mut T) -> Box<T>
1.4.0[src]
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.
Examples
let x = Box::new(5); let ptr = Box::into_raw(x); let x = unsafe { Box::from_raw(ptr) };
fn into_raw(b: Box<T>) -> *mut T
1.4.0[src]
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.
Note: this is an associated function, which means that you have
to call it as Box::into_raw(b)
instead of b.into_raw()
. This
is so that there is no conflict with a method on the inner type.
Examples
let x = Box::new(5); let ptr = Box::into_raw(x);
fn into_unique(b: Box<T>) -> Unique<T>
[src]
🔬 This is a nightly-only experimental API. (unique
)
needs an RFC to flesh out design
Consumes the Box
, returning the wrapped pointer as Unique<T>
.
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.
Note: this is an associated function, which means that you have
to call it as Box::into_unique(b)
instead of b.into_unique()
. This
is so that there is no conflict with a method on the inner type.
Examples
#![feature(unique)] fn main() { let x = Box::new(5); let ptr = Box::into_unique(x); }
impl Box<Any + 'static>
[src]
fn downcast<T>(self) -> Result<Box<T>, Box<Any + 'static>> where
T: Any,
[src]
T: Any,
Attempt to downcast the box to a concrete type.
Examples
use std::any::Any; fn print_if_string(value: Box<Any>) { if let Ok(string) = value.downcast::<String>() { println!("String ({}): {}", string.len(), string); } } fn main() { let my_string = "Hello World".to_string(); print_if_string(Box::new(my_string)); print_if_string(Box::new(0i8)); }
impl Box<Any + 'static + Send>
[src]
fn downcast<T>(self) -> Result<Box<T>, Box<Any + 'static + Send>> where
T: Any,
[src]
T: Any,
Attempt to downcast the box to a concrete type.
Examples
use std::any::Any; fn print_if_string(value: Box<Any + Send>) { if let Ok(string) = value.downcast::<String>() { println!("String ({}): {}", string.len(), string); } } fn main() { let my_string = "Hello World".to_string(); print_if_string(Box::new(my_string)); print_if_string(Box::new(0i8)); }
Trait Implementations
impl<T> Pointer for Box<T> where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Borrow<T> for Box<T> where
T: ?Sized,
1.1.0[src]
T: ?Sized,
impl<I> DoubleEndedIterator for Box<I> where
I: DoubleEndedIterator + ?Sized,
[src]
I: DoubleEndedIterator + ?Sized,
impl<T> Debug for Box<T> where
T: Debug + ?Sized,
[src]
T: Debug + ?Sized,
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter.
impl<T> PartialEq<Box<T>> for Box<T> where
T: PartialEq<T> + ?Sized,
[src]
T: PartialEq<T> + ?Sized,
fn eq(&self, other: &Box<T>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Box<T>) -> bool
[src]
This method tests for !=
.
impl<T> AsMut<T> for Box<T> where
T: ?Sized,
1.5.0[src]
T: ?Sized,
impl<T> Hash for Box<T> where
T: Hash + ?Sized,
[src]
T: Hash + ?Sized,
impl<T> AsRef<T> for Box<T> where
T: ?Sized,
1.5.0[src]
T: ?Sized,
impl<T> Eq for Box<T> where
T: Eq + ?Sized,
[src]
T: Eq + ?Sized,
impl<T> Drop for Box<T> where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Generator for Box<T> where
T: Generator + ?Sized,
[src]
T: Generator + ?Sized,
type Yield = <T as Generator>::Yield
generator_trait
)The type of value this generator yields. Read more
type Return = <T as Generator>::Return
generator_trait
)The type of value this generator returns. Read more
fn resume(
&mut self
) -> GeneratorState<<Box<T> as Generator>::Yield, <Box<T> as Generator>::Return>
[src]
&mut self
) -> GeneratorState<<Box<T> as Generator>::Yield, <Box<T> as Generator>::Return>
generator_trait
)Resumes the execution of this generator. Read more
impl From<String> for Box<str>
1.20.0[src]
impl<'a, T> From<&'a [T]> for Box<[T]> where
T: Copy,
1.17.0[src]
T: Copy,
impl<T> From<Vec<T>> for Box<[T]>
1.20.0[src]
impl From<Box<str>> for Box<[u8]>
1.19.0[src]
impl<T> From<T> for Box<T>
1.6.0[src]
impl<'a> From<&'a str> for Box<str>
1.17.0[src]
impl<T> DerefMut for Box<T> where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Boxed for Box<T>
[src]
type Data = T
placement_new_protocol
)type Place = IntermediateBox<T>
placement_new_protocol
)unsafe fn finalize(b: IntermediateBox<T>) -> Box<T>
[src]
placement_new_protocol
)impl<T> PartialOrd<Box<T>> for Box<T> where
T: PartialOrd<T> + ?Sized,
[src]
T: PartialOrd<T> + ?Sized,
fn partial_cmp(&self, other: &Box<T>) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Box<T>) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Box<T>) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn ge(&self, other: &Box<T>) -> bool
[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
fn gt(&self, other: &Box<T>) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<T> Clone for Box<T> where
T: Clone,
[src]
T: Clone,
fn clone(&self) -> Box<T>
[src]
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>)
[src]
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 Clone for Box<str>
1.3.0[src]
fn clone(&self) -> Box<str>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
[src]
Performs copy-assignment from source
. Read more
impl<T> Clone for Box<[T]> where
T: Clone,
1.3.0[src]
T: Clone,
fn clone(&self) -> Box<[T]>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
[src]
Performs copy-assignment from source
. Read more
impl<I> ExactSizeIterator for Box<I> where
I: ExactSizeIterator + ?Sized,
[src]
I: ExactSizeIterator + ?Sized,
impl<T> Ord for Box<T> where
T: Ord + ?Sized,
[src]
T: Ord + ?Sized,
impl<T> BorrowMut<T> for Box<T> where
T: ?Sized,
1.1.0[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Display for Box<T> where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<I> Iterator for Box<I> where
I: Iterator + ?Sized,
[src]
I: Iterator + ?Sized,
type Item = <I as Iterator>::Item
fn next(&mut self) -> Option<<I as Iterator>::Item>
[src]
fn size_hint(&self) -> (usize, Option<usize>)
[src]
fn nth(&mut self, n: usize) -> Option<<I as Iterator>::Item>
[src]
impl<T, U> CoerceUnsized<Box<U>> for Box<T> where
T: Unsize<U> + ?Sized,
U: ?Sized,
[src]
T: Unsize<U> + ?Sized,
U: ?Sized,
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a>
[src]
type Output = R
The returned type after the call operator is used.
extern "rust-call" fn call_once(self, args: A) -> R
[src]
fn_traits
)Performs the call operation.
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a + Send>
[src]
type Output = R
The returned type after the call operator is used.
extern "rust-call" fn call_once(self, args: A) -> R
[src]
fn_traits
)Performs the call operation.
impl<T> Deref for Box<T> where
T: ?Sized,
[src]
T: ?Sized,
type Target = T
The resulting type after dereferencing.
fn deref(&self) -> &T
[src]
Dereferences the value.
impl<T> Hasher for Box<T> where
T: Hasher + ?Sized,
1.22.0[src]
T: Hasher + ?Sized,
fn finish(&self) -> u64
[src]
fn write(&mut self, bytes: &[u8])
[src]
fn write_u8(&mut self, i: u8)
[src]
fn write_u16(&mut self, i: u16)
[src]
fn write_u32(&mut self, i: u32)
[src]
fn write_u64(&mut self, i: u64)
[src]
fn write_u128(&mut self, i: u128)
[src]
fn write_usize(&mut self, i: usize)
[src]
fn write_i8(&mut self, i: i8)
[src]
fn write_i16(&mut self, i: i16)
[src]
fn write_i32(&mut self, i: i32)
[src]
fn write_i64(&mut self, i: i64)
[src]
fn write_i128(&mut self, i: i128)
[src]
fn write_isize(&mut self, i: isize)
[src]
impl<I> FusedIterator for Box<I> where
I: FusedIterator + ?Sized,
[src]
I: FusedIterator + ?Sized,
impl Default for Box<str>
1.17.0[src]
impl<T> Default for Box<[T]>
[src]
impl<T> Default for Box<T> where
T: Default,
[src]
T: Default,