pub unsafe trait FlatStruct:
Copy
+ 'static
+ Send
+ Sync {
const TYPE_HASH: [u8; 16];
const WIRE_SIZE: usize = _;
// Provided methods
fn as_bytes(&self) -> &[u8] ⓘ { ... }
unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self { ... }
}Expand description
Marker trait for FlatData-capable types.
Spec quote (zerodds-flatdata-1.0 §1.1):
Guarantees:
Self: Copy(no Drop glue, plain bytes)Self: 'static(no lifetime reference)#[repr(C)]with a fixed, defined alignmentas_bytes()andfrom_bytes_unchecked()are safe by layout
§Safety
The implementer MUST ensure:
Selfis#[repr(C)](or#[repr(transparent)]over a singlerepr(C)type).- All fields are
FlatStructor primitive types without padding-sensitive UB (no#[repr(packed)]with pointer-aligned fields). Self: Copy(the trait bound enforces this).TYPE_HASHis unique for the exact wire-layout variant; on every schema change the hash MUST be regenerated.
Required Associated Constants§
Provided Associated Constants§
Provided Methods§
Sourcefn as_bytes(&self) -> &[u8] ⓘ
fn as_bytes(&self) -> &[u8] ⓘ
Returns the slot layout as a slice. Safe by layout — Self: Copy
repr(C)guarantee that the byte cast is defined.
Sourceunsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self
unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self
Reconstructs from a raw slice. The caller MUST:
- bytes.len() >= WIRE_SIZE
- bytes provenance valid for WIRE_SIZE
- type-hash verified beforehand (otherwise UB on alignment mismatch)
§Safety
See above.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".