I'm writing some basic bioinformatics code to transcribe DNA to RNA:
pub enum DnaNucleotide {
A,
C,
G,
T,
}
pub enum RnaNucleotide {
A,
C,
G,
U,
}
fn transcribe(base: &DnaNucleotide) -> RnaNucleotide {
match base {
DnaNucleotide::A => RnaNucleotide::A,
DnaNucleotide::C => RnaNucleotide::C,
DnaNucleotide::G => RnaNucleotide::G,
DnaNucleotide::T => RnaNucleotide::U,
}
}
Is there a way to get the compiler to do an exhaustivity check also on the right side of the match
statement, basically ensuring a 1-1 mapping between the two enums?
(A related question: The above is probably better represented with some kind of bijective map, but I don't want to lose the exhaustivity checking. Is there a better way?)