-
-
Save IanWhitney/b2ac83ae8195f5fc1a75 to your computer and use it in GitHub Desktop.
RNA Transcription example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fmt; | |
pub struct RibonucleicAcid { | |
strand: String | |
} | |
pub struct DeoxyribonucleicAcid { | |
strand: String | |
} | |
pub trait NucleicAcid { | |
fn new(strand: &str) -> Self; | |
} | |
impl NucleicAcid for RibonucleicAcid { | |
fn new(strand: &str) -> RibonucleicAcid { | |
RibonucleicAcid { | |
strand: strand.to_string() | |
} | |
} | |
} | |
impl NucleicAcid for DeoxyribonucleicAcid { | |
fn new(strand: &str) -> DeoxyribonucleicAcid { | |
DeoxyribonucleicAcid { | |
strand: strand.to_string() | |
} | |
} | |
} | |
impl RibonucleicAcid { | |
fn pair_of(base: char) -> char { | |
match base { | |
'C' => 'G', | |
'G' => 'C', | |
'A' => 'U', | |
'T' => 'A', | |
_ => base | |
} | |
} | |
} | |
impl DeoxyribonucleicAcid { | |
pub fn to_rna(&self) -> RibonucleicAcid { | |
let x: String = self.strand.chars().map(RibonucleicAcid::pair_of).collect(); | |
RibonucleicAcid::new(&x) | |
} | |
} | |
impl PartialEq for RibonucleicAcid { | |
fn eq(&self, other: &RibonucleicAcid) -> bool { | |
self.strand == other.strand | |
} | |
} | |
impl fmt::Debug for RibonucleicAcid { | |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
write!(f, "RibonucleicAcid {{ strand: {} }}", self.strand) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment