Consider the problem of generalizing Display/Debug. Given a struct Foo
, we want to auto derive some GUI for editing struct Foo
, where ATMOST 1 field can be "broken" at any time.
From a type perspective, we are given:
pub struct Foo {
a: A,
b: B,
c: C,
d: D,
}
and we want to generate something like:
pub enum Gen_Foo {
Done_A(Foo),
Done_B(Foo),
Done_C(Foo),
Done_D(Foo),
Edit_A { a: Gen_A, b: B, c: C, d: D },
Edit_B { a: A, b: Gen_B, c: C, d: D },
Edit_C { a: A, b: B, c: Gen_C, d: D },
Edit_D { a: A, b: B, c: C, d: Gen_D },
}
The four Done_*
arms are to indicate "the Struct is in a valid state, and we are selecting one of the arms". The Edit_*
fields are to indicate: the non-editing fields are valid, the edited field may or may not be valid.
Question: is there a name for this technique / pattern ? Is there a library / procedural macro that already done this?