-
Notifications
You must be signed in to change notification settings - Fork 36
Open
Description
Observation: The main pain point of enums is the repetitiveness of match-statements. Which are scattered around at different locations. This is good for adding and removing a new trait implementation (which is a local change of code). But it is not good for adding and removing enum-variants. Quick-error does code transformations to invert this for a specific set of traits.
Here is the (possibly crazy) idea: What about a code transformation that is generic in terms of the traits, too - like this example
IN
enum_transform!(
pub enum Foo {
X => {
#[define] Bar::baz(/* optional arguments*/) -> { Ok(()) }
},
Y => {
#[define] Bar::baz(/* optional arguments*/) -> { Err(()) }
}
}
impl Bar for Foo {
fn baz(&self, /* .. */) -> Result<(), ()> {
// ...
match *self
#[insert] { Bar::baz(/* optional arguments*/) }
// ...
}
}
)
OUT
pub enum Foo {
X,
Y
}
impl Bar for Foo {
fn baz(&self, /* .. */) -> Result<(), ()>
// ...
match *self {
X => { Ok(()) };
Y => { Err(()) };
}
// ...
}
}
If we had such a generic enum_transform macro, then
(a) quick_error could be rewritten in terms of enum_transform AND
(b) quick_error could itself could allow generic substitutions like this
EDIT:
- Minor corrections
Metadata
Metadata
Assignees
Labels
No labels