Skip to content

Make exhaust! macro to define inherent impl #91

@sanbox-irl

Description

@sanbox-irl

It would be nice if exhaust provided a macro_rules macro, which would appear as follows:

#[derive(exhaust::Exhaust)]
enum Foo {
  Bar,
  Baz,
}
exhaust::exhaust!(Foo);

which would expand to an inherent impl:

impl Foo {
  /// Appropriate doc comments here
  pub fn exhaust() -> impl Iterator<Item = Self> {
    <Self as exhaust::Exhaust>::exhaust()
  }
}

I freetyped the above, so it might not be correct.

This pattern has some precendence -- notably, this is what downcast-rs does. It is awkward and effectively a bodge and it can be fully implemented by users, but:

  • There are many times a user would want to implement this manually, so making that easier is a good idea
  • Users can choose to not use it and implement it themselves, particularly if they want to rename the main method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions