anathema icon indicating copy to clipboard operation
anathema copied to clipboard

Extended the State derive macro to work with enums and all valid structs

Open FishingHacks opened this issue 1 year ago • 3 comments

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 by Value<_>, 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.

FishingHacks avatar Sep 01 '24 09:09 FishingHacks

I have noticed that an enum without values will not turn into a state. I believe that is unintentionally-intentional because an enum without values is essentially the same as the Never (!) type in rust.

FishingHacks avatar Sep 01 '24 11:09 FishingHacks

Parking this until we've had a discussion on what to do with the unnamed structs.

One solution would be to prefix any state access with state.

togglebyte avatar Sep 08 '24 10:09 togglebyte

grrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

FishingHacks avatar Sep 10 '24 17:09 FishingHacks

:tbh_cry:

FishingHacks avatar Sep 19 '24 07:09 FishingHacks

Closed in favor of #70

FishingHacks avatar Sep 19 '24 13:09 FishingHacks