Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive an enum's min and max values #406

Open
musjj opened this issue Jan 27, 2025 · 3 comments
Open

Derive an enum's min and max values #406

musjj opened this issue Jan 27, 2025 · 3 comments

Comments

@musjj
Copy link

musjj commented Jan 27, 2025

It would be useful to have a derive macro that can automatically generate an enum's MIN and MAX.

For example, the following:

#[derive(MinMax)]
pub enum Foo {
    A,
    B,
    C,
}

Will generate this:

pub enum Foo {
    A,
    B,
    C,
}

impl Foo {
    const MIN: Self = Self::A;
    const MAX: Self = Self::C;
}
@martin-g
Copy link

You miss the type - enum in pub Foo

@musjj
Copy link
Author

musjj commented Jan 27, 2025

Whoops, fixed :)

@Peternator7
Copy link
Owner

Hi @musjj, could you elaborate on the scenario a little bit more? Is this just so you can match on patterns? I'm just not sure this scenario is super common.

fn is_min(&self) -> bool {
    matches!(Self::MIN, self)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants