1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2025-07-11 01:10:33 +02:00
Files
.github
dev
exercises
00_intro
01_variables
02_functions
03_if
04_primitive_types
05_vecs
06_move_semantics
07_structs
08_enums
09_strings
README.md
strings1.rs
strings2.rs
strings3.rs
strings4.rs
10_modules
11_hashmaps
12_options
13_error_handling
14_generics
15_traits
16_lifetimes
17_tests
18_iterators
19_smart_pointers
20_threads
21_macros
22_clippy
23_conversions
quizzes
README.md
rustlings-macros
solutions
src
tests
.editorconfig
.gitignore
.markdownlint.yml
.typos.toml
CHANGELOG.md
CONTRIBUTING.md
Cargo.lock
Cargo.toml
LICENSE
README.md
THIRD_PARTY_EXERCISES.md
oranda.json
release-hook.sh
rustlings/exercises/09_strings/strings4.rs

38 lines
1.0 KiB
Rust
Raw Normal View History

2024-06-22 12:51:21 +02:00
// Calls of this function should be replaced with calls of `string_slice` or `string`.
fn placeholder() {}
2022-07-14 13:01:40 +02:00
fn string_slice(arg: &str) {
2024-06-22 12:51:21 +02:00
println!("{arg}");
2022-07-14 13:01:40 +02:00
}
2024-07-06 12:53:14 -07:00
2022-07-14 13:01:40 +02:00
fn string(arg: String) {
2024-06-22 12:51:21 +02:00
println!("{arg}");
2022-07-14 13:01:40 +02:00
}
2024-06-22 12:51:21 +02:00
// 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.
2022-07-14 13:01:40 +02:00
fn main() {
2024-06-22 12:51:21 +02:00
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());
2022-07-14 13:01:40 +02:00
}