pub unsafe trait Flat: Sized {
// Required method
unsafe fn deep_copy(&self, p: &mut impl Patch, at: Pos);
}Expand description
Marker trait for types that can be stored in a Region.
§Safety
Implementors must satisfy all four invariants:
- No
Drop: The type must not implementDrop. The derive macro enforces this withconst { assert!(!needs_drop::<Self>()) }. - All fields are
Flat: Every field type must itself implementFlat. This is enforced by where-clause bounds in the generated impl. - No heap pointers: Indirection is expressed exclusively through
Near<T>andNearList<T>, which store self-relativei32offsets. Raw pointers,Box,Vec,String,Rc, etc. are forbidden. - Correct
deep_copy: Must write all transitively reachable data into the target buffer at the correct offsets, patching self-relative pointers.
§Derive macro
#[derive(Flat)] generates all of this automatically. For enums, a
#[repr(u8)] or #[repr(C, u8)] attribute is required (data variants
need #[repr(C, u8)]) so the discriminant byte is at a known position.
§Blanket impl
A blanket Emit<T> for &T impl exists, so T: Flat alone implies
&T: Emit<T> — enabling deep-copy via Region::trim and
re_splice_list without explicit builder types.
Required Methods§
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.