strings4.rs (992B)
1 // Calls of this function should be replaced with calls of `string_slice` or `string`. 2 fn placeholder() {} 3 4 fn string_slice(arg: &str) { 5 println!("{arg}"); 6 } 7 8 fn string(arg: String) { 9 println!("{arg}"); 10 } 11 12 // TODO: Here are a bunch of values - some are `String`, some are `&str`. 13 // Your task is to replace `placeholder(…)` with either `string_slice(…)` 14 // or `string(…)` depending on what you think each value is. 15 fn main() { 16 string_slice("blue"); 17 18 string("red".to_string()); 19 20 string(String::from("hi")); 21 22 string("rust is fun!".to_owned()); 23 24 string("nice weather".into()); 25 26 string(format!("Interpolation {}", "Station")); 27 28 // WARNING: This is byte indexing, not character indexing. 29 // Character indexing can be done using `s.chars().nth(INDEX)`. 30 string_slice(&String::from("abc")[0..1]); 31 32 string_slice(" hello there ".trim()); 33 34 string("Happy Monday!".replace("Mon", "Tues")); 35 36 string("mY sHiFt KeY iS sTiCkY".to_lowercase()); 37 }