Solve move semantics exercise 6 (#6)

This commit is contained in:
Jonathan Zernik 2022-06-07 00:24:09 -07:00 committed by GitHub
parent 52f25a7b62
commit 1b87ff5885
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,24 +2,22 @@
// Make me compile! `rustlings hint move_semantics6` for hints
// You can't change anything except adding or removing references
// I AM NOT DONE
fn main() {
let data = "Rust is great!".to_string();
get_char(data);
get_char(&data);
string_uppercase(&data);
string_uppercase(data);
}
// Should not take ownership
fn get_char(data: String) -> char {
fn get_char(data: &String) -> char {
data.chars().last().unwrap()
}
// Should take ownership
fn string_uppercase(mut data: &String) {
data = &data.to_uppercase();
fn string_uppercase(mut data: String) {
data = data.to_uppercase();
println!("{}", data);
}