Skip to content

Provide an option to derive const constructors #56

@Antikyth

Description

@Antikyth

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)
    }
}

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