mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-06-30 00:08:45 +00:00
30 lines
633 B
Rust
30 lines
633 B
Rust
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(format!("Interpolation {}", "Station"));
|
|
|
|
// WARNING: This is byte indexing, not character indexing.
|
|
// Character indexing can be done using `s.chars().nth(INDEX)`.
|
|
string_slice(&String::from("abc")[0..1]);
|
|
|
|
string_slice(" hello there ".trim());
|
|
|
|
string("Happy Monday!".replace("Mon", "Tues"));
|
|
|
|
string("mY sHiFt KeY iS sTiCkY".to_lowercase());
|
|
}
|