Expand description
Layout descriptors for struct or enum types with an inventory registry.
TypeLayout is derivable and exposes a const TypeLayoutInfo holding a type’s name, size, minimum alignment,
field offsets and enum variant discriminants.
use stable_type_layout::{Field, TypeLayout, TypeStructure};
#[derive(TypeLayout)]
#[repr(C)]
struct Foo {
a: u8,
b: u32,
}
const LAYOUT: stable_type_layout::TypeLayoutInfo = <Foo as TypeLayout>::TYPE_LAYOUT;
assert_eq!(LAYOUT.name, "Foo");
assert_eq!((LAYOUT.size, LAYOUT.align), (8, 4));
assert_eq!(
LAYOUT.structure,
TypeStructure::Struct { fields: &[Field { name: "a", offset: 0 }, Field { name: "b", offset: 4 }] }
);Types can additionally register! themselves into a crate-wide inventory registry, which can be used for
snapshot testing, so a field, variant reorder, or a size change can be caught.
Re-exports§
pub use inventory;
Macros§
- register
- Registers a type’s
TypeLayoutInfowith the registry read byallandrender.
Structs§
- Field
- A field’s name and byte offset within its type.
- Type
Layout Info - The concrete memory layout of a type: its name, size, minimum alignment and
TypeStructure. - Variant
- An enum variant’s name, declaration index and discriminant.
Enums§
- Type
Structure - Whether a type is a struct, union or enum, and the fields or variants it holds.
Traits§
- Type
Layout - A type whose memory layout is known at compile time.
Functions§
- all
- Every registered
TypeLayoutInfo, sorted by type name (deterministic order for snapshotting). - render
- Render every registered layout as a stable, human-readable string for snapshot assertions.
Derive Macros§
- Type
Layout - Implements
TypeLayout, recording the type’s size, alignment, field offsets and enum variant discriminants as aconst.