#[derive(Adapter)]
{
// Attributes available to this derive:
#[field]
}
Expand description
Derives flense’s Adapter implementations for the annotated fields of a
struct.
Annotate each field that should be lensable with #[field(...)]. Each entry
is either:
Marker- reference an existingFieldimplementation. The macro emits anunsafe impl Adapter<Marker>for the struct and a compile-time check that the field’s type is exactly<Marker as Field>::Type.new Marker- also mints a fresh marker typeMarker(inheriting the struct’s visibility) whoseField::Typeis the field’s declared type.new reflexive Marker- asnew Marker, and additionally emits anAdapter<Marker>impl for the field type itself (<Marker as Field>::Typeat offset zero), so a bare value of that type can be lensed asMarker. You could write thisunsafe implyourself; letting the derive emit it avoids needing to author and maintain aunsafeblock.
A single #[field(...)] may list several comma-separated entries, and the
attribute may be repeated on one field.
use flense::prelude::*;
enum Position {}
impl Field for Position {
type Type = [f32; 3];
}
#[derive(Adapter)]
struct Vertex {
#[field(Position)]
pos: [f32; 3],
#[field(new Color)]
color: [u8; 3],
}
#[derive(Adapter)]
struct Mesh {
#[field(Position)]
world_pos: [f32; 3],
#[field(Color)]
color: [u8; 3],
}