mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 05:09:19 +00:00
42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
// quiz2.rs
|
|
//
|
|
// This is a quiz for the following sections:
|
|
// - Strings
|
|
// - Vecs
|
|
// - Move semantics
|
|
// - Modules
|
|
// - Enums
|
|
//
|
|
// Let's build a little machine in the form of a function. As input, we're going
|
|
// to give a list of strings and commands. These commands determine what action
|
|
// is going to be applied to the string. It can either be:
|
|
// - Uppercase the string
|
|
// - Trim the string
|
|
// - Append "bar" to the string a specified amount of times
|
|
// The exact form of this will be:
|
|
// - The input is going to be a Vector of a 2-length tuple,
|
|
// the first element is the string, the second one is the command.
|
|
// - The output element is going to be a Vector of strings.
|
|
//
|
|
// No hints this time!
|
|
|
|
fn string_slice(arg: &str) {
|
|
println!("{}", arg);
|
|
}
|
|
fn string(arg: String) {
|
|
println!("{}", arg);
|
|
}
|
|
|
|
fn main() {
|
|
string_slice("blue");
|
|
string("red".to_string());
|
|
string(String::from("hi"));
|
|
string("rust is fun!".to_owned());
|
|
string_slice("nice weather".into());
|
|
string(format!("Interpolation {}", "Station"));
|
|
string_slice(&String::from("abc")[0..1]);
|
|
string_slice(" hello there ".trim());
|
|
string("Happy Monday!".to_string().replace("Mon", "Tues"));
|
|
string("mY sHiFt KeY iS sTiCkY".to_lowercase());
|
|
}
|