mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 12:49:18 +00:00
- Strings
- Vecs - Move semantics - Modules , Enums
This commit is contained in:
parent
3707571685
commit
915c53be64
@ -18,7 +18,7 @@
|
||||
// - The output element is going to be a Vector of strings.
|
||||
// Execute `rustlings hint quiz2` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
|
||||
pub enum Command {
|
||||
Uppercase,
|
||||
@ -30,11 +30,25 @@ 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!
|
||||
match command{
|
||||
Command::Uppercase => {
|
||||
let transformed_string = string.to_uppercase();
|
||||
output.push(transformed_string);
|
||||
}
|
||||
Command::Trim =>{
|
||||
let transformed_string = string.trim().to_string();
|
||||
output.push(transformed_string);
|
||||
}
|
||||
Command::Append(count) => {
|
||||
let appended_string = string.clone() + &"bar".repeat(*count);
|
||||
output.push(appended_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
output
|
||||
}
|
||||
@ -43,7 +57,7 @@ mod my_module {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// TODO: What do we have to import to have `transformer` in scope?
|
||||
use ???;
|
||||
use super::my_module::transformer;
|
||||
use super::Command;
|
||||
|
||||
#[test]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user