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

Consider using associated constants for the bitflag-like types #661

Closed
dtolnay opened this Issue Aug 18, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@dtolnay
Copy link

dtolnay commented Aug 18, 2017

The various Ready constructors currently work like this:

impl Ready {
    pub fn readable() -> Ready { /* ... */ }
    pub fn writable() -> Ready { /* ... */ }
}

With the associated constants feature of Rust 1.20, it could work like this:

impl Ready {
    pub const READABLE: Ready = /* ... */;
    pub const WRITABLE: Ready = /* ... */;
}

The constructors never do any work so they shouldn't need to be functions.

One advantage of constants is that they can be used in the pattern of a match statement.

@AndyGauge

This comment has been minimized.

Copy link
Contributor

AndyGauge commented Aug 21, 2017

I want to learn the associated constraints feature, so I'm going to give this a shot.

@dtolnay

This comment has been minimized.

Copy link
Author

dtolnay commented Aug 21, 2017

Great! Go for it. When it is done we will need to evaluate whether it is really an improvement over the current way.

@AndyGauge

This comment has been minimized.

Copy link
Contributor

AndyGauge commented Sep 1, 2017

So one problem with using Associated Constants is that it breaks previous builds of Rust. Currently, Travis tests version 1.13 which will fail with the implementation of the feature. I also wanted to capture @carllerche comment about now that rustc 1.20 has dropped, the feature can be implemented in 12 weeks (12/24ish).

@dethoter

This comment has been minimized.

Copy link
Contributor

dethoter commented Oct 31, 2017

I'm wondering why do you use struct(usize) and a number of associated constants instead of a plain enum?

@carllerche

This comment has been minimized.

Copy link
Owner

carllerche commented Jan 13, 2019

Mio will move away from bitflag style APIs in 0.7. This issue is no longer relevant.

@carllerche carllerche closed this Jan 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.