mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 12:49:18 +00:00
quiz 2 done ✅
This commit is contained in:
parent
6593e7ed86
commit
39f5ba14ce
@ -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,12 +28,35 @@ mod my_module {
|
||||
use super::Command;
|
||||
|
||||
// TODO: Complete the function signature!
|
||||
pub fn transformer(input: ???) -> ??? {
|
||||
pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
|
||||
// TODO: Complete the output declaration!
|
||||
let mut output: ??? = vec![];
|
||||
let mut output: Vec<String> = vec![];
|
||||
for (string, command) in input.iter() {
|
||||
// TODO: Complete the function body. You can do it!
|
||||
let out_res = match command {
|
||||
Command::Uppercase => {
|
||||
let res = string.to_uppercase();
|
||||
output.push(res);
|
||||
}
|
||||
Command::Trim => {
|
||||
let res = string.trim().to_string();
|
||||
output.push(res);
|
||||
}
|
||||
Command::Append(x) => {
|
||||
let res = append_fn(string, *x);
|
||||
output.push(res);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn append_fn(string: &str, count: usize) -> String {
|
||||
let mut result = String::from(string);
|
||||
for _ in 0..count {
|
||||
result += "bar";
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
output
|
||||
}
|
||||
}
|
||||
@ -43,8 +64,8 @@ mod my_module {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// TODO: What do we need to import to have `transformer` in scope?
|
||||
use ???;
|
||||
use super::Command;
|
||||
use crate::my_module::transformer;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
|
||||
BIN
temp_11956_ThreadId1.exe
Normal file
BIN
temp_11956_ThreadId1.exe
Normal file
Binary file not shown.
BIN
temp_12120_ThreadId1.exe
Normal file
BIN
temp_12120_ThreadId1.exe
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user