Struct pwasm_std::Box1.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]

[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]

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) };

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);

[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]

[src]

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]

[src]

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]

[src]

impl<T> Borrow<T> for Box<T> where
    T: ?Sized
1.1.0
[src]

[src]

impl<I> DoubleEndedIterator for Box<I> where
    I: DoubleEndedIterator + ?Sized
[src]

[src]

impl<T> Debug for Box<T> where
    T: Debug + ?Sized
[src]

[src]

Formats the value using the given formatter.

impl<T> PartialEq<Box<T>> for Box<T> where
    T: PartialEq<T> + ?Sized
[src]

[src]

[src]

impl<T> AsMut<T> for Box<T> where
    T: ?Sized
1.5.0
[src]

[src]

impl<T> Hash for Box<T> where
    T: Hash + ?Sized
[src]

[src]

impl<T> AsRef<T> for Box<T> where
    T: ?Sized
1.5.0
[src]

[src]

Performs the conversion.

impl<T> Eq for Box<T> where
    T: Eq + ?Sized
[src]

impl<T> Drop for Box<T> where
    T: ?Sized
[src]

[src]

impl<T> Generator for Box<T> where
    T: Generator + ?Sized
[src]

🔬 This is a nightly-only experimental API. (generator_trait)

🔬 This is a nightly-only experimental API. (generator_trait)

[src]

🔬 This is a nightly-only experimental API. (generator_trait)

impl<T> From<Vec<T>> for Box<[T]>
1.20.0
[src]

[src]

impl From<String> for Box<str>
1.20.0
[src]

[src]

impl<'a, T> From<&'a [T]> for Box<[T]> where
    T: Copy
1.17.0
[src]

[src]

impl From<Box<str>> for Box<[u8]>
1.19.0
[src]

[src]

impl<T> From<T> for Box<T>
1.6.0
[src]

[src]

impl<'a> From<&'a str> for Box<str>
1.17.0
[src]

[src]

impl<T> DerefMut for Box<T> where
    T: ?Sized
[src]

[src]

impl<T> Boxed for Box<T>
[src]

🔬 This is a nightly-only experimental API. (placement_new_protocol)

🔬 This is a nightly-only experimental API. (placement_new_protocol)

[src]

🔬 This is a nightly-only experimental API. (placement_new_protocol)

impl<T> PartialOrd<Box<T>> for Box<T> where
    T: PartialOrd<T> + ?Sized
[src]

[src]

[src]

[src]

[src]

[src]

impl<I> ExactSizeIterator for Box<I> where
    I: ExactSizeIterator + ?Sized
[src]

[src]

[src]

impl<T> Clone for Box<[T]> where
    T: Clone
1.3.0
[src]

[src]

impl Clone for Box<str>
1.3.0
[src]

[src]

impl<T> Clone for Box<T> where
    T: Clone
[src]

[src]

Returns a new box with a clone() of this box's contents.

Examples

let x = Box::new(5);
let y = x.clone();

[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<T> Ord for Box<T> where
    T: Ord + ?Sized
[src]

[src]

impl<T> BorrowMut<T> for Box<T> where
    T: ?Sized
1.1.0
[src]

[src]

impl<T> Display for Box<T> where
    T: Display + ?Sized
[src]

[src]

impl<I> Iterator for Box<I> where
    I: Iterator + ?Sized
[src]

[src]

[src]

[src]

impl<T, U> CoerceUnsized<Box<U>> for Box<T> where
    T: Unsize<U> + ?Sized,
    U: ?Sized
[src]

impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a>
[src]

🔬 This is a nightly-only experimental API. (fnbox)

will be deprecated if and when Box<FnOnce> becomes usable

[src]

🔬 This is a nightly-only experimental API. (fnbox)

will be deprecated if and when Box<FnOnce> becomes usable

impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a + Send>
[src]

🔬 This is a nightly-only experimental API. (fnbox)

will be deprecated if and when Box<FnOnce> becomes usable

[src]

🔬 This is a nightly-only experimental API. (fnbox)

will be deprecated if and when Box<FnOnce> becomes usable

impl<T> Deref for Box<T> where
    T: ?Sized
[src]

The resulting type after dereferencing.

[src]

Dereferences the value.

impl<T> Hasher for Box<T> where
    T: Hasher + ?Sized
1.22.0
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<I> FusedIterator for Box<I> where
    I: FusedIterator + ?Sized
[src]

impl Default for Box<str>
1.17.0
[src]

[src]

impl<T> Default for Box<T> where
    T: Default
[src]

[src]

Creates a Box<T>, with the Default value for T.

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

[src]