[][src]Struct generic_vec::raw::UninitBuffer

#[repr(transparent)]pub struct UninitBuffer<T, A = u8>(_);

An uninitialized storage. This storage can store values of any type that has an alignment smaller of equal to T or A.

UninitBuffer has a max capacity of round_up(size_of::<T>(), align_::<A>()) / size_of::<Element>() elements.

i.e. UninitBuffer<[i32; 12]> can store 12 i32s, but UninitBuffer<[i32; 1], u64> can store 2 i32s. Because u64 is aligned to 8 bytes, so round_up(4 bytes, 8 bytes) / 4 bytes == 2`

You can query the capacity with UninitBuffer::capacity

assert_eq!(UninitBuffer::<[i32; 12]>::capacity::<i32>(), 12);
assert_eq!(UninitBuffer::<[i32; 1], u64>::capacity::<i32>(), 2);
assert_eq!(UninitBuffer::<[i32; 1]>::capacity::<u64>(), 0);

In memory representation

This type is represented in memory as

#[repr(C)]
struct AlignedBuffer<T, A> {
    align: [A; 0],
    value: T,
}

The size of the buffer is determined by type paramter T, and the alignment is the maximum alignment of T and A. This means that A should be used to ensure a certain alignment.

Implementations

impl<T, A> UninitBuffer<T, A>[src]

pub const fn capacity<U>() -> usize[src]

Get the capacity of this buffer for a given element type

pub const fn uninit() -> Self[src]

Create a new uninitialized array storage

pub const fn new(value: T) -> Self[src]

Create a new uninitialized array storage with the given value

Trait Implementations

impl<T, A> Clone for UninitBuffer<T, A>[src]

impl<T, A> Default for UninitBuffer<T, A>[src]

impl<T, A> Send for UninitBuffer<T, A>[src]

impl<U, T, A> Storage<U> for UninitBuffer<T, A>[src]

impl<U, T, A> StorageWithCapacity<U> for UninitBuffer<T, A>[src]

impl<T, A> Sync for UninitBuffer<T, A>[src]

Auto Trait Implementations

impl<T, A> RefUnwindSafe for UninitBuffer<T, A> where
    A: RefUnwindSafe,
    T: RefUnwindSafe

impl<T, A> Unpin for UninitBuffer<T, A> where
    A: Unpin,
    T: Unpin

impl<T, A> UnwindSafe for UninitBuffer<T, A> where
    A: UnwindSafe,
    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.