pub unsafe trait Pod:
Copy
+ Send
+ 'static { }Expand description
Marker trait for types safe to use with seqlock-stamped ring buffers.
A type is Pod (“Plain Old Data”) if every possible bit pattern
of size_of::<T>() bytes represents a valid value of T. This is
stricter than Copy — it excludes types where certain bit patterns
are undefined behavior, such as bool (only 0/1 valid), char
(must be a valid Unicode scalar), NonZero* (must be nonzero), and
references (must point to valid memory).
§Why this matters
The seqlock read protocol performs an optimistic non-atomic read that
may observe a partially-written (“torn”) value. If the torn bit pattern
violates a type’s validity invariant, this is undefined behavior even
though the value is detected and discarded by the stamp check. Pod
guarantees that no bit pattern is invalid, making torn reads harmless.
§Safety
Implementors must ensure:
TisCopy(no destructor, no move semantics).TisSend(safe to transfer across threads).- Every possible bit pattern of
size_of::<T>()bytes is a validT. Thas no padding bytes that carry validity constraints.
§Pre-implemented types
Pod is implemented for all primitive numeric types, arrays of Pod
types, and tuples up to 12 elements of Pod types.
For user-defined structs, use unsafe impl:
#[repr(C)]
#[derive(Clone, Copy)]
struct Quote {
price: f64,
volume: u32,
_pad: u32,
}
// SAFETY: Quote is #[repr(C)], all fields are plain numerics,
// and every bit pattern is a valid Quote.
unsafe impl photon_ring::Pod for Quote {}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.