TrackedStruct derive enums #584
Labels
bikeshed 🚴♀️
Debating API details and the like
rfc
Active discussion about a possible future feature
Milestone
I sometimes find myself declaring tracked structs that effectively just wrap an enum:
I wonder if it'd be nice to make a
salsa::TrackedStruct
derive for this pattern? I am imagining that it generates a tracked struct as above, with additional methods named after each variant that return anOption<(...)>
with the data from the variant (the equivalent ofmatch x.kind(db) { Variant1(...) => Some((...)), _ => None }
.The name of the tracked struct would by default be taken from the enum -- we would split the last word (
Kind
) and the other words (Foo
, in this case) and name the struct after the first part and the field after the second (kind
). This would be overridable with an attribute.We would (could?) also add an inherent
new
method to the enum to permitFooKind(...).new(db)
instead ofFoo::new(db, FooKind(...))
. Not sure about that.So something like:
Then you could do
Foo::new(db, FooKind::Variant1(...))
.The text was updated successfully, but these errors were encountered: