mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 05:09:19 +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.
|
// - The output element is going to be a Vector of strings.
|
||||||
// Execute `rustlings hint quiz2` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint quiz2` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
Uppercase,
|
Uppercase,
|
||||||
@ -30,11 +30,25 @@ mod my_module {
|
|||||||
use super::Command;
|
use super::Command;
|
||||||
|
|
||||||
// TODO: Complete the function signature!
|
// TODO: Complete the function signature!
|
||||||
pub fn transformer(input: ???) -> ??? {
|
pub fn transformer(input: Vec<(String,Command)>) -> Vec<String> {
|
||||||
// TODO: Complete the output declaration!
|
// TODO: Complete the output declaration!
|
||||||
let mut output: ??? = vec![];
|
let mut output: Vec<String> = vec![];
|
||||||
for (string, command) in input.iter() {
|
for (string, command) in input.iter() {
|
||||||
// TODO: Complete the function body. You can do it!
|
// 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
|
output
|
||||||
}
|
}
|
||||||
@ -43,7 +57,7 @@ mod my_module {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
// TODO: What do we have to import to have `transformer` in scope?
|
// TODO: What do we have to import to have `transformer` in scope?
|
||||||
use ???;
|
use super::my_module::transformer;
|
||||||
use super::Command;
|
use super::Command;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user