exercism/rust/test/main.rs

43 lines
No EOL
1.3 KiB
Rust

pub fn encode(inp_string: &'static str) -> String{
let x = tokenize(inp_string);
let x_tuple = tupleize(x);
let x_converted = tup_convert(x_tuple);
let mut encoded_string: String = "".to_string();
for each in x_converted.into_iter() {
encoded_string.push_str(each.as_str());
}
return encoded_string;
}
// Tokenizes a to-be-encoded string
fn tokenize(inp_string: &'static str) -> Vec<&str>{
return vec!["AAA","BB","C", "DDDD"]
}
// "Tuple-izes" a to-be-encoded vector
fn tupleize(inp_vec: Vec<&str>) -> Vec<(char, usize)>{
let mut tupleized: Vec<(char, usize)> = Vec::new();
for each in inp_vec {
tupleized.push((each.chars().next().unwrap(), each.len()));
}
return tupleized;
}
// Converts tuple into a vector of strings
fn tup_convert(inp_tuple: Vec<(char, usize)>) -> Vec<String>{
let mut converted: Vec<String> = Vec::new();
for i in 0..inp_tuple.len() {
let converted_element: &str = &(inp_tuple[i].1.to_string().as_str().to_owned() + inp_tuple[i].0.to_string().as_str());
// let converted_element: &'static str = string_converted_element;
converted.push(converted_element.to_owned());
}
return converted;
}
pub fn decode(inp_string: &'static str) -> String{
return String::from("")
}
fn main(){
print!("{}", encode("hi"));
}