anathema
anathema copied to clipboard
Extended the State derive macro to work with enums and all valid structs
I changed the State derive macro so that it now can derive the State for Union, Unnamed and Named structs and enums.
These were previously impossible to derive and had to be implemented by hand:
#[derive(State)]
struct MyState;
#[derive(State)]
struct MyState(Value<u32>);
#[derive(State)]
enum MyEnum {
A,
B{ value: Value<u32> },
C(Value<u32>)
}
Note: The derive macro doesn't check that all values of the enum are
Value<_>
, but because it uses functions defined byValue<_>
, this should otherwise throw an error. I am not sure if or how such behavior would be possible to implement as Field::Type::Path(Path) doesn't contain the qualified path (anathema_state::value::Value
) but instead the unqualified path. To qualify this path, the code would have to know the imported types, but as of right now, I am unsure how to get access to those. Maybe not ensuring that however is an intended feature as other types could implement the functions defined by Value.