Struct granite::SparseStorageSlot[][src]

#[repr(transparent)]
pub struct SparseStorageSlot<T>(_);

A slot inside a sparse storage.

This is an opaque structure, only used for the purpose of a SparseStorage being validly declarable, because leaking private types through generic argument defaults is impossible, and it’d be impossible to declare the type of the backing storage if it was explicitly different.

Size and representation

The contents of this section are an implementation detail. Unless stated otherwise, relying on those for memory safety may cause undefined behavior.

The structure is actually a newtype wrapper around an concrete implementation for storing the value.

Union version

If the union_optimizations feature flag is enabled, the layout looks like this:

struct SlotUnionBased<T> {
    discrim: u8,
    data: SlotUnion<T>,
}
union SlotUnion<T> {
    hole_link: usize,
    element: T,
}

The hole_link member of the union is actually Option<usize> under the hood. If None, the 0b0000_0010 bit in discrim is set to zero; otherwise, it is set to 1. For soundness purposes, the value of hole_link is never uninitialized and is instead set to an arbitrary value when it’s supposed to be None.

Exact size and alignment

The following members contribute to size:

  • either usize (1 pointer) or T (arbitrary size)
  • discriminant: one u8 (1 byte)
  • padding: 1 pointer minus 1 byte for the discriminant to fit in, can be more due to the alignment of T

Total size: 2 pointers (16 bytes on 64-bit systems, 8 bytes on 32-bit systems) or more depending on the size of T if it’s over the size of 1 pointer Total alignment: the same as a pointer (largest primitive alignment), but may be more if T specifies a bigger exotic alignment explicitly

Enum version

If the union_optimizations feature flag is disabled (always the case on the current stable compiler as of Rust 1.46), the following enum-based representation is used instead:

enum SlotEnumBased<T> {
   Element(T),
   Hole(Option<usize>),
}

Exact size and alignment

The following members contribute to size:

  • either Option<usize> (2 pointers: one for the value, another one for discriminant and alignment) or T (arbitrary size)
  • discriminant and padding: at least 1 pointer wide, can be more due to the alignment of T

Total size: 3 pointers (24 bytes on 64-bit systems, 12 bytes on 32-bit systems) or more depending on the size of T if it’s over the size of 2 pointers Total alignment: the same as a pointer (largest primitive alignment), but may be more if T specifies a bigger exotic alignment explicitly

Trait Implementations

impl<T: Debug> Debug for Slot<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Slot<T> where
    T: RefUnwindSafe

impl<T> Send for Slot<T> where
    T: Send

impl<T> Sync for Slot<T> where
    T: Sync

impl<T> Unpin for Slot<T> where
    T: Unpin

impl<T> UnwindSafe for Slot<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, 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.