std::boxed

This module is used for heap allocation.

A very simple way to allocate memory on the heap, provide ownership, and drop when out of scope.
  • impl<T> Box<T>
    • fn new(x:T) -> Box<T>: Allocates memory on the heap and places x into it
  • impl <T> Box<T> where T: ?Sized
    • unsafe fn from_raw(raw: *mut T) -> Box<T>: Constructs a box from a raw pointer. After creation, the pointer is owned by the new Box. It is unsafe for this very reason; the Box destructor will call the destructor of T and free the allocated memory. This may lead to double freeing that will cause a crash.
    • fn into_raw(b: Box<T> -> *mut T: Consumes the box and returns the wrapped raw pointer.
  • impl Box<Any + 'static>
    • fn downcast<T>(self) -> Result<Box<T>, Box<Any + 'static>> ...

Get Learning Rust now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.