change from review

This commit is contained in:
Kallu-A 2022-02-04 22:58:58 +01:00
parent 683cad89f3
commit 7030abe87d
2 changed files with 8 additions and 6 deletions

View File

@ -6,8 +6,8 @@
fn main() {
let data = "Rust is great!".to_string();
println!("{}", get_char(data));
get_char(data);
string_uppercase(&data);
}
@ -20,5 +20,6 @@ fn get_char(data: String) -> char {
// Should take ownership
fn string_uppercase(mut data: &String) {
data = &data.to_uppercase();
println!("{}", data);
}
}

View File

@ -230,10 +230,11 @@ To find the answer, you can consult the book section "References and Borrowing":
https://doc.rust-lang.org/stable/book/ch04-02-references-and-borrowing.html
The first problem is that `get_char` is taking ownership of the string.
So `data` is moved and can't be used for `string_uppercase`
- `get_char` should borrow data (use &)
One it's fix now is `string_uppercase` who's trying to change a borrowed value
so it's the opposite of `get_char` (remove &)
"""
`data` is moved to `get_char` first, meaning that `string_uppercase` cannot manipulate the data.
Once you've fixed that, `string_uppercase`'s function signature will also need to be adjusted.
Can you figure out how?
Another hint: it has to do with the `&` character."""
# PRIMITIVE TYPES