You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
currently Enums are not supported by the derive macro.
I would therefore like to propose a way to interpret enums in ramhorns.
If this finds a consensus I am willing to try to implement this.
General Enum Handling
I think to access enum items Mustache sections are fitting as they include the notion of false values or emptiness:
enum Status {
Available,
OutOfStock,
}
Would get accessed like this:
The Item is currently:
{{#Available}}
available
{{/Available}}
{{#OutOfStock}}
out of stock
{{/OutOfStock}}
This leaves us with how to handle different types of enums:
Fieldless Enumerations. I.e. No item has data attached, this is much like a c enum and can be interpreted as integer type
Enums with attached data.
2.1 An Item can have a Struct like form
2.2 An Item can have a Tuple like form
2.3 An Item can have no data attached
Fieldless Enumerations
I think these are pretty easy to handle as shown in the example above. The question is how to handle the numerical value of these. We could use the same syntax as for tuple like enums as discussed below.
Enums with attached data
If any item of an enum has attached data the whole enum can't be interpreted as integer anymore according to the Rust reference. We have to therefore define how the different Item cases are handled. I assume that all attached data types implement the Content trait.
Struct like
The easiest is probably the struct like form, this I believe can just be handled like normal structs. We open a section and access the fields by name in the section.
Tuple like
Handling the tuple like form is more complicated as we don't have an identifier for the fields. We could work around this with numbers as identifiers where the number n identifies the nth Item like so:
We currently have
{{#Numerical}}
{{1}}
{{/Numerical}}
{{#WithUnit}}
{{1}} {{2}}
{{/WithUnit}}
in stock.
No data attached
Since there is no data attached the section would just check whether it is truthy or not. No data can be accessed as there is none present.
Summary
I believe this would give much more flexibility to ramhorns while keeping mostly true to the mustache templates ideas. And prevent the need to unwrap all enum variants into their own Option just to be able to use them with ramhorns.
I am looking forward to your thoughts and feedback!
The text was updated successfully, but these errors were encountered:
Hi,
currently Enums are not supported by the derive macro.
I would therefore like to propose a way to interpret enums in ramhorns.
If this finds a consensus I am willing to try to implement this.
General Enum Handling
I think to access enum items Mustache sections are fitting as they include the notion of false values or emptiness:
Would get accessed like this:
This leaves us with how to handle different types of enums:
Enum Types:
Following enum types are currently present in rust:
2.1 An Item can have a Struct like form
2.2 An Item can have a Tuple like form
2.3 An Item can have no data attached
Fieldless Enumerations
I think these are pretty easy to handle as shown in the example above. The question is how to handle the numerical value of these. We could use the same syntax as for tuple like enums as discussed below.
Enums with attached data
If any item of an enum has attached data the whole enum can't be interpreted as integer anymore according to the Rust reference. We have to therefore define how the different Item cases are handled. I assume that all attached data types implement the Content trait.
Struct like
The easiest is probably the struct like form, this I believe can just be handled like normal structs. We open a section and access the fields by name in the section.
Tuple like
Handling the tuple like form is more complicated as we don't have an identifier for the fields. We could work around this with numbers as identifiers where the number n identifies the nth Item like so:
We could access these like this:
No data attached
Since there is no data attached the section would just check whether it is truthy or not. No data can be accessed as there is none present.
Summary
I believe this would give much more flexibility to ramhorns while keeping mostly true to the mustache templates ideas. And prevent the need to unwrap all enum variants into their own
Option
just to be able to use them with ramhorns.I am looking forward to your thoughts and feedback!
The text was updated successfully, but these errors were encountered: