Sha256: 4ed177988da25f6e0f6ebc09e4edb071a759728d6e07543b637b89226da21300

Contents?: true

Size: 898 Bytes

Versions: 31

Compression:

Stored size: 898 Bytes

Contents

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

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

#[derive(PartialEq, Eq, Debug)]
pub struct DNA {
    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 DNA {
    pub fn new(nucleotides: &str) -> DNA {
        DNA { nucleotides: nucleotides.to_string() }
    }

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

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
trackler-2.2.1.83 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.82 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.81 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.80 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.79 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.78 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.77 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.76 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.75 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.74 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.73 tracks/rust/exercises/rna-transcription/example.rs