Derive Macro blade_macros::Flat

source ·
#[derive(Flat)]
Expand description

Derive the Flat for a type.

Can either be used on a struct that has every field already implementing blade_asset::Flat:

#[derive(blade_macros::Flat)]
struct FlatData<'a> {
   array: [u32; 2],
   single: f32,
   slice: &'a [u16],
}

The struct may have a lifetime describing borrowed data members. Borrowing is needed for zero-copy deserialization.

Alternatively, can be used on a transparent wrapper to force blade_asset::Flat implementation even if the wrapped type doesn’t implement it:

#[derive(Clone, Copy)]
#[repr(u32)]
#[non_exhaustive]
enum Foo {
    A,
    B,
}
#[derive(blade_macros::Flat, Clone, Copy)]
#[repr(transparent)]
struct FooWrap(Foo);

This can be particularly useful for types like bytemuck::Pod implementors, or plain non-exhaustive enums from 3rd party crates.