Skip to main content

Flat

Trait Flat 

Source
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:

  1. No Drop: The type must not implement Drop. The derive macro enforces this with const { assert!(!needs_drop::<Self>()) }.
  2. All fields are Flat: Every field type must itself implement Flat. This is enforced by where-clause bounds in the generated impl.
  3. No heap pointers: Indirection is expressed exclusively through Near<T> and NearList<T>, which store self-relative i32 offsets. Raw pointers, Box, Vec, String, Rc, etc. are forbidden.
  4. 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§

Source

unsafe fn deep_copy(&self, p: &mut impl Patch, at: Pos)

Deep-copy self into the buffer at position at, patching all self-relative pointers so they remain valid in the new location.

§Safety

at must be a position previously allocated for Self in the same buffer.

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.

Implementations on Foreign Types§

Source§

impl Flat for Infallible

Source§

unsafe fn deep_copy(&self, _p: &mut impl Patch, _at: Pos)

Source§

impl Flat for bool

Source§

unsafe fn deep_copy(&self, p: &mut impl Patch, at: Pos)

Source§

impl Flat for i32

Source§

unsafe fn deep_copy(&self, p: &mut impl Patch, at: Pos)

Source§

impl Flat for i64

Source§

unsafe fn deep_copy(&self, p: &mut impl Patch, at: Pos)

Source§

impl Flat for u8

Source§

unsafe fn deep_copy(&self, p: &mut impl Patch, at: Pos)

Source§

impl Flat for u16

Source§

unsafe fn deep_copy(&self, p: &mut impl Patch, at: Pos)

Source§

impl Flat for u32

Source§

unsafe fn deep_copy(&self, p: &mut impl Patch, at: Pos)

Source§

impl Flat for u64

Source§

unsafe fn deep_copy(&self, p: &mut impl Patch, at: Pos)

Source§

impl<A: Flat, B: Flat> Flat for (A, B)

Source§

unsafe fn deep_copy(&self, p: &mut impl Patch, at: Pos)

Source§

impl<T: Flat> Flat for Option<T>

Source§

unsafe fn deep_copy(&self, p: &mut impl Patch, at: Pos)

Source§

impl<T: Flat, const N: usize> Flat for [T; N]

Source§

unsafe fn deep_copy(&self, p: &mut impl Patch, at: Pos)

Implementors§

Source§

impl<T> Flat for Near<T>

Source§

impl<T> Flat for NearList<T>