Skip to main content

Emit

Trait Emit 

Source
pub unsafe trait Emit<T>: Sized {
    // Required method
    unsafe fn write_at(self, p: &mut impl Patch, at: Pos);

    // Provided method
    fn emit(self, p: &mut impl Patch) -> Pos
       where T: Flat { ... }
}
Expand description

Builder trait for constructing values in a Region.

Implementors describe how to serialize a value of type T into a region buffer. The #[derive(Flat)] macro generates builder types (e.g. Foo::make(...)) that implement this trait, enabling fully declarative, tree-shaped region construction via Region::new.

§Safety

Implementations must correctly write exactly size_of::<T>() bytes at the given position, with correct field offsets and pointer patching. This invariant is upheld by the derive macro; manual implementations must ensure the same.

§Key implementations

TypeBehavior
Primitives (u32, bool, …)Self-emit via write_flat
&T where T: FlatDeep-copy via Flat::deep_copy (blanket impl)
Ref<'id, T>Deep-copy from existing buffer position
InfallibleUnreachable (used for empty NearList iterators)
Generated buildersField-by-field construction with pointer patching

Required Methods§

Source

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

Write this builder’s data at position at.

§Safety

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

Provided Methods§

Source

fn emit(self, p: &mut impl Patch) -> Pos
where T: Flat,

Reserve space for T, write this builder’s data, and return the position.

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 Emit<bool> for bool

Source§

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

Source§

impl Emit<i32> for i32

Source§

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

Source§

impl Emit<i64> for i64

Source§

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

Source§

impl Emit<u8> for u8

Source§

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

Source§

impl Emit<u16> for u16

Source§

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

Source§

impl Emit<u32> for u32

Source§

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

Source§

impl Emit<u64> for u64

Source§

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

Source§

impl<A: Flat, B: Flat, BA: Emit<A>, BB: Emit<B>> Emit<(A, B)> for (BA, BB)

Source§

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

Source§

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

Source§

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

Source§

impl<T: Flat> Emit<T> for Infallible

Source§

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

Source§

impl<T: Flat> Emit<T> for &T

Source§

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

Source§

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

Source§

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

Implementors§

Source§

impl<T: Flat> Emit<T> for Ref<'_, T>