问题
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:
Yes, just import the enum variants with the use
keyword.
pub enum Player {
Black,
White,
}
use Player::*;
来源:https://stackoverflow.com/questions/64266286/is-there-an-easier-way-to-make-enum-constants-visible