Skip to content

Instantly share code, notes, and snippets.

@cristianrasch
Created August 19, 2016 14:14
Show Gist options
  • Save cristianrasch/72ea8d2a4cc804207aa8e97405c43205 to your computer and use it in GitHub Desktop.
Save cristianrasch/72ea8d2a4cc804207aa8e97405c43205 to your computer and use it in GitHub Desktop.
#[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