resolved quiz2

This commit is contained in:
Samuele Iacoponi
2026-01-10 18:30:31 +01:00
parent f3b42e5620
commit 9ef3441dba
2 changed files with 111 additions and 4 deletions

View File

@@ -28,6 +28,26 @@ mod my_module {
// TODO: Complete the function as described above.
// pub fn transformer(input: ???) -> ??? { ??? }
pub fn transformer(input: Vec<(String,Command)>) -> Vec<String> {
//Iterate the input vector to get String and Command and put in a result vector
input
.into_iter()
.map(|(string, command)|{ // Descructuring in string, command of each vector's entry
match command{
Command::Uppercase => string.to_uppercase(),
Command::Trim => string.trim().to_string(),
Command::Append(n) => {
let mut res_string = string;
for _i in 1..=n{
res_string.push_str("bar")
}
res_string
}
}
})
.collect() // Put everything in result
}
}
fn main() {
@@ -37,7 +57,8 @@ fn main() {
#[cfg(test)]
mod tests {
// TODO: What do we need to import to have `transformer` in scope?
// use ???;
// This way... is he going to search in quiz2.rs?
use crate::my_module::transformer;
use super::Command;
#[test]