Successful null solution for rna-transcription

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 { })
    }
}

Hah, interesting. We always compare two RNA values in the tests. One converted from a DNA and one created directly. If you don’t store anything in the RNA, every instance will compare equal to any other… PR with fix: rna-transcription: add test to avoid cheesing by senekor · Pull Request #2151 · exercism/rust · GitHub

2 Likes