I managed to solve the rna-transcription exercise without actually doing any transcription (see below). Perhaps there are one or two missing test cases? I’d be happy to create a PR to add them if needed.
#[derive(Debug, PartialEq, Eq)]
pub struct Dna {
}
#[derive(Debug, PartialEq, Eq)]
pub struct Rna {
}
fn validate(given: &str, allowed: &str) -> Result<(), usize> {
for (i, c) in given.chars().enumerate() {
if !allowed.contains(c) {
return Err(i);
}
}
Ok(())
}
impl Dna {
pub fn new(dna: &str) -> Result<Dna, usize> {
validate(dna, "ACGT").map(|_| Dna { })
}
pub fn into_rna(self) -> Rna {
Rna { }
}
}
impl Rna {
pub fn new(rna: &str) -> Result<Rna, usize> {
validate(rna, "ACGU").map(|_| Rna { })
}
}