2024-06-10 17:10:02 +08:00

28 lines
565 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// move_semantics6.rs
//
// 您只能添加或刪除引用reference不能更改其他任何內容。
//
// 執行 `rustlings hint move_semantics6` 或使用 `hint` watch 子命令來獲取提示。
// I AM NOT DONE
fn main() {
let data = "Rust is great!".to_string();
get_char(data);
string_uppercase(&data);
}
// 不應該取得所有權
fn get_char(data: String) -> char {
data.chars().last().unwrap()
}
// 應該取得所有權
fn string_uppercase(mut data: &String) {
data = &data.to_uppercase();
println!("{}", data);
}