Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRange / tuple enums #1493
Comments
This comment has been minimized.
This comment has been minimized.
|
I ask: What you're suggesting is type-level ranges? If so, are you proposing ability to do arithmetic operations on them? |
This comment has been minimized.
This comment has been minimized.
KalitaAlexey
commented
Feb 8, 2016
|
@nixpulvis How do you want to assign
or
I'd like to write second variant. But I don't know is it possible? |
This comment has been minimized.
This comment has been minimized.
|
@KalitaAlexey I could see a number of ways possibly. These are the two options that most jump out at me. One treats the created enum very much like enums are treated today, the other required the compiler to know that enum CardValue(0...13);
struct Card {
value: CardValue,
suit: Suit,
}
let card = Card {
value: CardValue(1),
suit: Suit::Clubs,
};
// Or
struct Card {
value: (0...13),
suit: Suit,
}
let card = Card {
value: 1,
suit: Suit::Hearts,
}; |
nrc
added
the
T-lang
label
Aug 18, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nixpulvis commentedFeb 8, 2016
I've been thinking about writing a strict type for a deck of cards in rust (for example), and I've found myself really wanting this feature. The idea is to allow ranges or tuples in the definition of an
enum. This would allow Rust to express (easily) larger numbers of variants for enums. This would play nicely with enum refinement typing, as I've read about elsewhere.