Expand description
Compile-time classification of Rust types according to Rust-specified type properties.
§Classification Axes
RustSpec describes a type across the following axes:
layout: representation stability.size: statically sized, metadata-sized, or extern-type-like shape.Alignment: whether ABI alignment is one or greater than one.trap: whether the value representation has trap values.niche: whether a type has a stable, unstable, or no niche value.
§Layout
Describes total reachable (through pointer indirection) representation stability:
Stable: compiler-guaranteed representation.Unstable: representation is not guaranteed.
§Size
Describes compile-time size and pointer metadata shape:
size::Sized<Zero>: compile-time known zero-sized type.size::Sized<Gt<Zero>>: compile-time known non-zero-sized type.size::MetaSized<size::SliceLike>: dynamically sized slice-like type.size::MetaSized<size::DynTraitLike>: dynamically sized trait-object-like type.size::ExternTypeLike: dynamically sized extern-type-like type.
§Alignment
Whether ABI alignment is exactly one or greater than one.
§Trap
Describes total reachable (through pointer indirection) value-representation validity:
layout::Robust: every bit pattern is valid.layout::NonRobust: some bit patterns are trap/invalid values.
§Niche
Describes whether and what kind of niche is available for the type:
niche::WithoutNiche: no niche is available.niche::WithNiche<Stable>: compiler-guaranteed niche.niche::WithNiche<Unstable>: niche exists but is not guaranteed.
§How to Use
Derive RustSpec for your types, then use its associated marker families as bounds when implementing other traits:
use disjoint_impls::disjoint_impls;
use rust_spec::{
RustSpec, Stable, Unstable,
niche::{WithNiche, WithoutNiche}
};
#[derive(RustSpec)]
struct Header {
id: u32,
flags: u16,
}
disjoint_impls! {
trait NullableEncoding {
const NEEDS_TAG: bool;
}
impl<T: RustSpec<Niche = WithoutNiche>> NullableEncoding for T {
const NEEDS_TAG: bool = true;
}
impl<T: RustSpec<Niche = WithNiche<Stable>>> NullableEncoding for T {
const NEEDS_TAG: bool = false;
}
impl<T: RustSpec<Niche = WithNiche<Unstable>>> NullableEncoding for T {
const NEEDS_TAG: bool = false;
}
}
const HEADER_OPTION_NEEDS_TAG: bool = Header::NEEDS_TAG;Modules§
- layout
- Representation stability and trap/robustness classification.
- niche
- Logic related to the conversion of
Option<T>to and from FFI-compatible representation - size
Structs§
- Gt
- Marker for a statically sized type greater than the given threshold.
Enums§
- One
- Marker for ABI alignment one.
- Stable
- Marker for a compiler-guaranteed representation or niche.
- Unstable
- Marker for a representation or niche that is not compiler-guaranteed.
- Zero
- Marker for a zero-sized type.
Traits§
- Max
- Type-level maximum used to combine alignment categories.
- Rust
Spec - Joined Rust-spec classification of a type.