feat: add strings3.rs exercise

This commit is contained in:
Denton24646 2022-06-20 17:31:07 -04:00
parent d27f5a7d41
commit aa87cae4d3
2 changed files with 43 additions and 0 deletions

View 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
}

View File

@ -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]]