Sha256: b9b1f5e960e9c81951b89dac6f93965c573b2a2831d770c40305c52aa6317902

Contents?: true

Size: 1.01 KB

Versions: 110

Compression:

Stored size: 1.01 KB

Contents

#[derive(PartialEq, Eq, Debug)]
pub struct RibonucleicAcid {
    nucleotides: String
}

impl RibonucleicAcid {
    pub fn new(nucleotides: &str) -> RibonucleicAcid {
        RibonucleicAcid { nucleotides: nucleotides.to_string() }
    }
}

#[derive(PartialEq, Eq, Debug)]
pub struct DeoxyribonucleicAcid {
    nucleotides: String
}

fn transcribe_dna_rna(c: char) -> Option<char> {
    match c {
        'C' => Some('G'),
        'G' => Some('C'),
        'A' => Some('U'),
        'T' => Some('A'),
        _   => None
    }
}

impl DeoxyribonucleicAcid {
    pub fn new(nucleotides: &str) -> DeoxyribonucleicAcid {
        DeoxyribonucleicAcid { nucleotides: nucleotides.to_string() }
    }

    pub fn to_rna(&self) -> Result<RibonucleicAcid, ()> {
        let rna_nucleotides: String = self.nucleotides.chars().filter_map(transcribe_dna_rna).collect();
        if rna_nucleotides.len() == self.nucleotides.len() {
            Ok(RibonucleicAcid { nucleotides: rna_nucleotides })
        } else {
            Err(())
        }
    }
}

Version data entries

110 entries across 110 versions & 1 rubygems

Version Path
trackler-2.2.1.12 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.11 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.10 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.9 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.8 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.7 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.6 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.5 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.4 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.3 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.2 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.1 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.0 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.0.6 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.0.5 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.0.4 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.0.3 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.0.2 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.0.1 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.0.0 tracks/rust/exercises/rna-transcription/example.rs