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

Provide an option to derive const constructors #56

Open
Antikyth opened this issue Jan 2, 2023 · 0 comments
Open

Provide an option to derive const constructors #56

Antikyth opened this issue Jan 2, 2023 · 0 comments

Comments

@Antikyth
Copy link

Antikyth commented Jan 2, 2023

Related: #29

This crate seems very useful to me, but unfortunately it provides no way to derive const constructors, and because of that I cannot use it for my project. I can't think why this wouldn't be the default, but nonetheless, an opt-in feature flag perhaps would be really helpful.

I would like to be able to use the constructors like so:

pub struct Atom(u32);

pub const PRIMARY: Atom = Atom::new(1);
pub const SECONDARY: Atom = Atom::new(2);
pub const ARC: Atom = Atom::new(3);
pub const ATOM: Atom = Atom::new(4);
pub const BITMAP: Atom = Atom::new(5);

Where Atom is used in implementing a protocol that pre-defines these constants with the corresponding IDs. That means using a const fn like so:

impl Atom {
    #[must_use]
    pub const fn new(id: u32) -> Self {
        Self(id)
    }
}
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

1 participant