fndtoa(dna:&str)->String{dna.chars().map(|c|matchc{'G'|'C'|'A'=>c,'T'=>'U',_=>panic!("you did this to yourself"),}).collect()}fnmain(){forxin&["TTTT","GCAT","GACCGCCGCC","💩"]{println!("{}=>{}",x,dtoa(x));}}
"Rust"
useitertools::Itertools;// 0.9.0#[derive(Debug)]enumDToAError{Scat(usize,char),}useDToAError::*;implstd::fmt::DisplayforDToAError{fnfmt(&self,f:&mutstd::fmt::Formatter)->std::fmt::Result{matchself{Scat(i,c)=>write!(f,"Is this a joke? At index {}, what is `{}`?! No you can't \"have the processed values back\", get out!",i,c),}}}implstd::error::ErrorforDToAError{fnsource(&self)->Option<&(dynstd::error::Error+'static)>{None}}fndtoa(dna:&str)->Result<String,DToAError>{dna.chars().enumerate().map(|(i,c)|{Ok(matchc{'G'|'C'|'A'=>c,'T'=>'U',_=>returnErr(Scat(i,c)),})}).fold_results(String::with_capacity(dna.len()),|muts,c|{s.push(c);s})}fnmain(){forxin&["TTTT","GCAT","GACCGCCGCC","💩"]{matchdtoa(x){Ok(res)=>println!("{}=>{}",x,res),Err(err)=>println!("{}=>OOPS: {}",x,err),}}}
Roost
"Rust"
It works lol
When you don't listen at all