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

Use enums for enumeration constants #254

Closed
3 tasks
fiveop opened this issue Jan 28, 2016 · 4 comments · Fixed by #792
Closed
3 tasks

Use enums for enumeration constants #254

fiveop opened this issue Jan 28, 2016 · 4 comments · Fixed by #792

Comments

@fiveop
Copy link
Contributor

fiveop commented Jan 28, 2016

Just like we use bitflags! for flags, we could use enums for enumeration constants. They would provide a zero cost, type safe abstraction over the current primitive type constants.

A (partial) list of places to use enums:

  • sys::mman::MADV_*
  • sys::quota::Q_*
  • sys::signal::SIG*
@kamalmarhubi
Copy link
Member

👍

homu added a commit that referenced this issue Feb 28, 2016
Add introduction/constants/enumeration/uninitialized to CONVENTIONS.

I have added new sections to the file. I would like the usual suspects to read them critically and offer critique.

When have agreed to add certain versions I will add Issues to track our progress in getting the code to follow the conventions. For two of the sections they already exist in #254 and #264.
@kamalmarhubi
Copy link
Member

Added a task list.

@kamalmarhubi
Copy link
Member

Synonyms will not be allowed as variants. This results in E0081:

enum Foo {
    Bar = 0,
    Baz = 0,
    Quux = 1,
}

playground

@kamalmarhubi
Copy link
Member

We may be able to do something like this:

pub enum Foo {
    BAR = 0,
    QUUX = 1,
}
use Foo::*;

pub const BAZ: Foo = BAR;

fn main() {
    println!("{}", match BAR {
        // We can even *match* using the synonym!
        BAZ => "Is it a BAR? Could be a BAZ too!",
        _ => "Not Ba{r,z} =(",
    });
}

playground

wginolas added a commit to wginolas/nix that referenced this issue Nov 5, 2017
Some enums which use different names for values than libc still set the
discriminators manually.

closes nix-rust#254
wginolas added a commit to wginolas/nix that referenced this issue Nov 5, 2017
Some enums which use different names for values than libc still set the
discriminators manually.

closes nix-rust#254
@Susurrus Susurrus added this to the 1.0 milestone Nov 5, 2017
wginolas added a commit to wginolas/nix that referenced this issue Nov 5, 2017
Some enums which use different names for values than libc still set the
discriminators manually.

closes nix-rust#254
bors bot added a commit that referenced this issue Nov 11, 2017
792: Use libc_enum! where possible r=Susurrus a=wginolas

Some enums which use different names for values than libc still set the
discriminators manually.

closes #254
@bors bors bot closed this as completed in #792 Nov 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants