Created
August 19, 2016 14:14
-
-
Save cristianrasch/72ea8d2a4cc804207aa8e97405c43205 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#[derive(Debug, PartialEq)] | |
pub struct RibonucleicAcid<'a> { | |
nucleotides: &'a str, | |
} | |
impl<'a> RibonucleicAcid<'a> { | |
pub fn new(nucleotides: &str) -> RibonucleicAcid { | |
RibonucleicAcid { nucleotides: nucleotides } | |
} | |
} | |
#[derive(Debug, PartialEq)] | |
pub struct DeoxyribonucleicAcid<'a> { | |
nucleotides: &'a str, | |
} | |
impl<'a> DeoxyribonucleicAcid<'a> { | |
pub fn new(nucleotides: &str) -> DeoxyribonucleicAcid { | |
DeoxyribonucleicAcid { nucleotides: nucleotides } | |
} | |
pub fn to_rna(&self) -> RibonucleicAcid { | |
let nt: String = self.nucleotides.chars().map(|c| match c { | |
'G' => 'C', | |
'C' => 'G', | |
'T' => 'A', | |
'A' => 'U', | |
_ => ' ', | |
}).collect(); | |
RibonucleicAcid::new(&nt) // <- how do I make nt live long enough? (i.e. transfer ownership of the String to the struct) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment