mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 21:29:18 +00:00
Option2
This commit is contained in:
parent
48350051bc
commit
0b26dbae59
@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
// Execute `rustlings hint hashmaps3` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint hashmaps3` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
struct Team {
|
struct Team {
|
||||||
|
|||||||
@ -18,8 +18,6 @@
|
|||||||
// - The output element is going to be a Vector of strings.
|
// - The output element is going to be a Vector of strings.
|
||||||
// No hints this time!
|
// No hints this time!
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
Uppercase,
|
Uppercase,
|
||||||
Trim,
|
Trim,
|
||||||
@ -28,13 +26,20 @@ pub enum Command {
|
|||||||
|
|
||||||
mod my_module {
|
mod my_module {
|
||||||
use super::Command;
|
use super::Command;
|
||||||
|
pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
|
||||||
// TODO: Complete the function signature!
|
let mut output: Vec<String> = vec![];
|
||||||
pub fn transformer(input: ???) -> ??? {
|
|
||||||
// TODO: Complete the output declaration!
|
|
||||||
let mut output: ??? = vec![];
|
|
||||||
for (string, command) in input.iter() {
|
for (string, command) in input.iter() {
|
||||||
// TODO: Complete the function body. You can do it!
|
output.push(match command {
|
||||||
|
Command::Uppercase => string.to_uppercase(),
|
||||||
|
Command::Trim => string.trim().into(),
|
||||||
|
Command::Append(times) => {
|
||||||
|
let mut string = string.clone();
|
||||||
|
for _ in 0..*times {
|
||||||
|
string += "bar";
|
||||||
|
}
|
||||||
|
string
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
@ -43,7 +48,7 @@ mod my_module {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
// TODO: What do we need to import to have `transformer` in scope?
|
// TODO: What do we need to import to have `transformer` in scope?
|
||||||
use ???;
|
use my_module::transformer;
|
||||||
use super::Command;
|
use super::Command;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user