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) orT
(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) orT
(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
Auto Trait Implementations
impl<T> RefUnwindSafe for Slot<T> where
T: RefUnwindSafe,
impl<T> RefUnwindSafe for Slot<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Slot<T> where
T: UnwindSafe,
impl<T> UnwindSafe for Slot<T> where
T: UnwindSafe,