[][src]Struct aligned_box::AlignedBox

pub struct AlignedBox<T: ?Sized> { /* fields omitted */ }

A wrapper around std::boxed::Box which allows allocating aligned heap memory. An instance of AlignedBox<T> consists of a Box<T> and the std::alloc::Layout that has been used to allocate the referenced memory.

Implementations

impl<T: ?Sized> AlignedBox<T>[src]

pub fn into_raw_parts(from: AlignedBox<T>) -> (*mut T, Layout)[src]

Decompose the AlignedBox into a raw pointer and the layout used during allocation. The caller of this function becomes responsible for proper deallocation of the memory behind the pointer. This can for example be done by reconstructing the AlignedBox using AlignedBox::from_raw_parts.

pub unsafe fn from_raw_parts(ptr: *mut T, layout: Layout) -> AlignedBox<T>[src]

Construct an AlignedBox from a raw pointer and the layout that has been used to allocate the memory behind that pointer. After calling this function, the pointer is owned by the AlignedBox. In particular, the memory will be freed when the AlignedBox is dropped. This is only safe if the given layout is the same as the one that was used during memory allocation.

Safety

The function is unsafe because improper use can lead to issues, such as double-free. Also, behavior is undefined if the given layout does not correspond to the one used for allocation.

impl<T> AlignedBox<T>[src]

pub fn new(alignment: usize, value: T) -> Result<AlignedBox<T>, Box<dyn Error>>[src]

Store value of type T on the heap, making sure that it is aligned to a multiple of alignment. It is also checked if alignment is a valid alignment for type T or increased to a valid alignment otherwise.

Example

Place value 17 of type i32 on the heap, aligned to 64 bytes:

use aligned_box::AlignedBox;

let b = AlignedBox::<i32>::new(64, 17);

impl<T: Default> AlignedBox<[T]>[src]

pub fn slice_from_default(
    alignment: usize,
    nelems: usize
) -> Result<AlignedBox<[T]>, Box<dyn Error>>
[src]

Allocate memory for nelems values of type T on the heap, making sure that it is aligned to a multiple of alignment. All values are initialized by the default value of type T. It is also checked if alignment is a valid alignment for type T or increased to a valid alignment otherwise.

Example

Allocate memory for 1024 values of type f32 on the heap, aligned to 128 bytes. Values are initialized by their default value:

use aligned_box::AlignedBox;

let b = AlignedBox::<[f32]>::slice_from_default(128, 1024);

impl<T: Copy> AlignedBox<[T]>[src]

pub fn slice_from_value(
    alignment: usize,
    nelems: usize,
    value: T
) -> Result<AlignedBox<[T]>, Box<dyn Error>>
[src]

Allocate memory for nelems values of type T on the heap, making sure that it is aligned to a multiple of alignment. All values are initialized by copies of value. It is also checked if alignment is a valid alignment for type T or increased to a valid alignment otherwise.

Example

Allocate memory for 1024 values of type f32 on the heap, aligned to 128 bytes. All values are initialized with PI:

use aligned_box::AlignedBox;

let b = AlignedBox::<[f32]>::slice_from_value(128, 1024, std::f32::consts::PI);

Trait Implementations

impl<T: Clone + ?Sized> Clone for AlignedBox<T>[src]

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

type Target = T

The resulting type after dereferencing.

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

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

Auto Trait Implementations

impl<T: ?Sized> RefUnwindSafe for AlignedBox<T> where
    T: RefUnwindSafe

impl<T: ?Sized> Send for AlignedBox<T> where
    T: Send

impl<T: ?Sized> Sync for AlignedBox<T> where
    T: Sync

impl<T: ?Sized> Unpin for AlignedBox<T>

impl<T: ?Sized> UnwindSafe for AlignedBox<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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

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

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.