Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::HashMap;
- fn main() {
- let attribs = vec!["alpha", "beta", "gamma", "delta"];
- let specials = vec!["beta", "delta"];
- print_attribs(attribs, specials);
- }
- // expected output: one *two three *four
- fn print_attribs(attribs: Vec<&str>, specials: Vec<&str>) {
- let m = get_map();
- let mut output: Vec<String> = Vec::new();
- for item in attribs {
- let v = m.get(item).unwrap();
- let mut w = String::new();
- if specials.contains(&item) {
- w.push('*');
- }
- w.push_str(v);
- output.push(w);
- }
- // do something with 'output'...
- println!("\noutput = {:?} ", output);
- }
- fn get_map() -> HashMap<String, String> {
- let mut m: HashMap<String, String> = HashMap::new();
- m.insert(String::from("alpha"), String::from("one"));
- m.insert(String::from("epsilon"), String::from("five"));
- m.insert(String::from("beta"), String::from("two"));
- m.insert(String::from("gamma"), String::from("three"));
- m.insert(String::from("delta"), String::from("four"));
- m
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement