Skip to content

custom implementations #14

Description

@colin-kiegel

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!(pubenumFoo{X => {
#[define]Bar::baz(/* optional arguments*/) -> {Ok(())}},Y => {
#[define]Bar::baz(/* optional arguments*/) -> {Err(())}}}implBarforFoo{fn baz(&self,/* .. */) -> Result<(),()> {// ...match*self
#[insert]{Bar::baz(/* optional arguments*/)}// ...}})

OUT

pubenumFoo{X,Y}implBarforFoo{fnbaz(&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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions