Is there an easier way to make enum constants visible?

Viewed 135

I find myself writing stuff like this:

pub enum Player {BLACK, WHITE,}

const BLACK: Player = Player::BLACK;
const WHITE: Player = Player::WHITE;

The reason, of course, being to avoid noise in match expressions and other uses of the constants.

Is there an easier way to achieve this?

1 Answers

Yes, just import the enum variants with the use keyword.

pub enum Player {
    Black,
    White,
}

use Player::*;
Related