-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add move_semantics6.rs exercise (#908)
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// move_semantics6.rs | ||
// 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); | ||
|
||
string_uppercase(&data); | ||
} | ||
|
||
// Should not take ownership | ||
fn get_char(data: String) -> char { | ||
data.chars().last().unwrap() | ||
} | ||
|
||
// Should take ownership | ||
fn string_uppercase(mut data: &String) { | ||
data = &data.to_uppercase(); | ||
|
||
println!("{}", data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters