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.103 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.102 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.101 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.100 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.99 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.98 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.97 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.96 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.95 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.94 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.93 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.92 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.91 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.90 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.89 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.88 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.87 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.86 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.85 tracks/rust/exercises/rna-transcription/example.rs
trackler-2.2.1.84 tracks/rust/exercises/rna-transcription/example.rs