mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-25 23:10:30 +00:00
move_semantics5: Move main
to the end
This commit is contained in:
parent
e512928df5
commit
59d6b852af
2 changed files with 16 additions and 16 deletions
|
@ -3,14 +3,6 @@
|
||||||
// TODO: Fix the compiler errors without changing anything except adding or
|
// TODO: Fix the compiler errors without changing anything except adding or
|
||||||
// removing references (the character `&`).
|
// removing references (the character `&`).
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let data = "Rust is great!".to_string();
|
|
||||||
|
|
||||||
get_char(data);
|
|
||||||
|
|
||||||
string_uppercase(&data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shouldn't take ownership
|
// Shouldn't take ownership
|
||||||
fn get_char(data: String) -> char {
|
fn get_char(data: String) -> char {
|
||||||
data.chars().last().unwrap()
|
data.chars().last().unwrap()
|
||||||
|
@ -22,3 +14,11 @@ fn string_uppercase(mut data: &String) {
|
||||||
|
|
||||||
println!("{data}");
|
println!("{data}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let data = "Rust is great!".to_string();
|
||||||
|
|
||||||
|
get_char(data);
|
||||||
|
|
||||||
|
string_uppercase(&data);
|
||||||
|
}
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
#![allow(clippy::ptr_arg)]
|
#![allow(clippy::ptr_arg)]
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let data = "Rust is great!".to_string();
|
|
||||||
|
|
||||||
get_char(&data);
|
|
||||||
|
|
||||||
string_uppercase(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Borrows instead of taking ownership.
|
// Borrows instead of taking ownership.
|
||||||
// It is recommended to use `&str` instead of `&String` here. But this is
|
// It is recommended to use `&str` instead of `&String` here. But this is
|
||||||
// enough for now because we didn't handle strings yet.
|
// enough for now because we didn't handle strings yet.
|
||||||
|
@ -21,3 +13,11 @@ fn string_uppercase(mut data: String) {
|
||||||
|
|
||||||
println!("{data}");
|
println!("{data}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let data = "Rust is great!".to_string();
|
||||||
|
|
||||||
|
get_char(&data);
|
||||||
|
|
||||||
|
string_uppercase(data);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue