mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 12:49:18 +00:00
Complete quiz2
This commit is contained in:
parent
65d5fdf7d1
commit
8859a5b724
@ -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,
|
||||
@ -29,12 +27,17 @@ pub enum Command {
|
||||
mod my_module {
|
||||
use super::Command;
|
||||
|
||||
// TODO: Complete the function signature!
|
||||
pub fn transformer(input: ???) -> ??? {
|
||||
// TODO: Complete the output declaration!
|
||||
let mut output: ??? = vec![];
|
||||
pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
|
||||
let mut output: Vec<String> = vec![];
|
||||
for (string, command) in input.iter() {
|
||||
// TODO: Complete the function body. You can do it!
|
||||
output.push(match command {
|
||||
Command::Uppercase => String::from(string.to_uppercase()),
|
||||
Command::Trim => String::from(string.trim()),
|
||||
Command::Append(times) => {
|
||||
let bars = "bar".repeat(*times);
|
||||
format!("{string}{bars}")
|
||||
}
|
||||
});
|
||||
}
|
||||
output
|
||||
}
|
||||
@ -42,9 +45,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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user