summaryrefslogtreecommitdiff
path: root/exercises/09_strings/strings4.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-07-05 13:39:50 +0200
committermo8it <mo8it@proton.me>2024-07-05 13:39:50 +0200
commit7123c7ae3a9605fbe962e4ef0a0f1424cd16fef8 (patch)
treec67f7e62bb9a179ae4fdbab492501cb6847e64c7 /exercises/09_strings/strings4.rs
parent77b687d501771c24bd83294d97b8e6f9ffa92d6b (diff)
parent4d9c346a173bb722b929f3ea3c00f84954483e24 (diff)
Merge remote-tracking branch 'upstream/main' into fix-enum-variant-inconsistency
Diffstat (limited to 'exercises/09_strings/strings4.rs')
-rw-r--r--exercises/09_strings/strings4.rs50
1 files changed, 28 insertions, 22 deletions
diff --git a/exercises/09_strings/strings4.rs b/exercises/09_strings/strings4.rs
index e8c54ac..9d9eb48 100644
--- a/exercises/09_strings/strings4.rs
+++ b/exercises/09_strings/strings4.rs
@@ -1,30 +1,36 @@
-// strings4.rs
-//
-// Ok, here are a bunch of values-- some are `String`s, some are `&str`s. Your
-// task is to call one of these two functions on each value depending on what
-// you think each value is. That is, add either `string_slice` or `string`
-// before the parentheses on each line. If you're right, it will compile!
-//
-// No hints this time!
-
-// I AM NOT DONE
+// Calls of this function should be replaced with calls of `string_slice` or `string`.
+fn placeholder() {}
fn string_slice(arg: &str) {
- println!("{}", arg);
+ println!("{arg}");
}
fn string(arg: String) {
- println!("{}", arg);
+ println!("{arg}");
}
+// TODO: Here are a bunch of values - some are `String`, some are `&str`.
+// Your task is to replace `placeholder(…)` with either `string_slice(…)`
+// or `string(…)` depending on what you think each value is.
fn main() {
- ???("blue");
- ???("red".to_string());
- ???(String::from("hi"));
- ???("rust is fun!".to_owned());
- ???("nice weather".into());
- ???(format!("Interpolation {}", "Station"));
- ???(&String::from("abc")[0..1]);
- ???(" hello there ".trim());
- ???("Happy Monday!".to_string().replace("Mon", "Tues"));
- ???("mY sHiFt KeY iS sTiCkY".to_lowercase());
+ placeholder("blue");
+
+ placeholder("red".to_string());
+
+ placeholder(String::from("hi"));
+
+ placeholder("rust is fun!".to_owned());
+
+ placeholder("nice weather".into());
+
+ placeholder(format!("Interpolation {}", "Station"));
+
+ // WARNING: This is byte indexing, not character indexing.
+ // Character indexing can be done using `s.chars().nth(INDEX)`.
+ placeholder(&String::from("abc")[0..1]);
+
+ placeholder(" hello there ".trim());
+
+ placeholder("Happy Monday!".replace("Mon", "Tues"));
+
+ placeholder("mY sHiFt KeY iS sTiCkY".to_lowercase());
}