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.72 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.71 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.70 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.69 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.68 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.67 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.66 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.65 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.64 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.63 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.62 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.61 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.60 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.59 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.58 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.57 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.56 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.55 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.54 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.53 tracks/rust/exercises/rna-transcription/example.rs