mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 21:29:18 +00:00
feat: add strings3.rs exercise
This commit is contained in:
parent
d27f5a7d41
commit
aa87cae4d3
33
exercises/strings/strings3.rs
Normal file
33
exercises/strings/strings3.rs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// strings3.rs
|
||||||
|
// Make me compile without changing the function signature!
|
||||||
|
// Execute `rustlings hint strings3` for hints ;)
|
||||||
|
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let hello = String::from("hello");
|
||||||
|
let suffix = " there!";
|
||||||
|
|
||||||
|
let result = append_str(hello, suffix);
|
||||||
|
|
||||||
|
assert_eq!(result, "hello there!".to_string());
|
||||||
|
println!("{}", result);
|
||||||
|
|
||||||
|
let lo = String::from("lo");
|
||||||
|
let result = append_char(lo, 'l');
|
||||||
|
|
||||||
|
assert_eq!(result, "lol");
|
||||||
|
println!("{}", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn append_str(mut s: String, suffix: &str) -> String {
|
||||||
|
// TODO: append the suffix to s
|
||||||
|
|
||||||
|
s
|
||||||
|
}
|
||||||
|
|
||||||
|
fn append_char(mut s: String, suffix: char) -> String {
|
||||||
|
// TODO append the suffix to s
|
||||||
|
|
||||||
|
s
|
||||||
|
}
|
||||||
10
info.toml
10
info.toml
@ -475,6 +475,16 @@ Yes, it would be really easy to fix this by just changing the value bound to `wo
|
|||||||
string slice instead of a `String`, wouldn't it?? There is a way to add one character to line
|
string slice instead of a `String`, wouldn't it?? There is a way to add one character to line
|
||||||
9, though, that will coerce the `String` into a string slice."""
|
9, though, that will coerce the `String` into a string slice."""
|
||||||
|
|
||||||
|
[[exercises]]
|
||||||
|
name = "strings3"
|
||||||
|
path = "exercises/strings/strings3.rs"
|
||||||
|
mode = "compile"
|
||||||
|
hint = """
|
||||||
|
There are several easy ways to append to a String! In this case use push_str() to append
|
||||||
|
a string slice to a String, and push() to append a character to a String.
|
||||||
|
Learn more at https://doc.rust-lang.org/book/ch08-02-strings.html#updating-a-string
|
||||||
|
"""
|
||||||
|
|
||||||
# TEST 2
|
# TEST 2
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user