From eabd709365c0ae05eeb8e786568798ca44d58fc6 Mon Sep 17 00:00:00 2001 From: ACvanWyk Date: Sat, 25 Feb 2023 20:31:17 +0200 Subject: [PATCH] Complete quiz2 --- exercises/quiz2.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index 5c42dae0..fa6ddcc9 100644 --- a/exercises/quiz2.rs +++ b/exercises/quiz2.rs @@ -18,8 +18,6 @@ // - The output element is going to be a Vector of strings. // No hints this time! -// I AM NOT DONE - pub enum Command { Uppercase, Trim, @@ -30,11 +28,16 @@ mod my_module { use super::Command; // TODO: Complete the function signature! - pub fn transformer(input: ???) -> ??? { + pub fn transformer(input: Vec<(String, Command)>) -> Vec { // TODO: Complete the output declaration! - let mut output: ??? = vec![]; + let mut output: Vec = vec![]; for (string, command) in input.iter() { // TODO: Complete the function body. You can do it! + match command { + Command::Uppercase => output.push(string.to_uppercase()), + Command::Trim => output.push(string.trim().to_owned()), + Command::Append(size) => output.push(string.to_owned() + &"bar".repeat(*size)), + } } output } @@ -43,7 +46,7 @@ mod my_module { #[cfg(test)] mod tests { // TODO: What do we need to import to have `transformer` in scope? - use ???; + use super::my_module::transformer; use super::Command; #[test]