diff options
Diffstat (limited to 'exercises/06_move_semantics/move_semantics5.rs')
| -rw-r--r-- | exercises/06_move_semantics/move_semantics5.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/exercises/06_move_semantics/move_semantics5.rs b/exercises/06_move_semantics/move_semantics5.rs index 267bdcc..fc59338 100644 --- a/exercises/06_move_semantics/move_semantics5.rs +++ b/exercises/06_move_semantics/move_semantics5.rs @@ -1,19 +1,24 @@ -// move_semantics5.rs -// -// Make me compile only by reordering the lines in `main()`, but without adding, -// changing or removing any of them. -// -// Execute `rustlings hint move_semantics5` or use the `hint` watch subcommand -// for a hint. +#![allow(clippy::ptr_arg)] -// I AM NOT DONE +// TODO: Fix the compiler errors without changing anything except adding or +// removing references (the character `&`). -#[test] fn main() { - let mut x = 100; - let y = &mut x; - let z = &mut x; - *y += 100; - *z += 1000; - assert_eq!(x, 1200); + let data = "Rust is great!".to_string(); + + get_char(data); + + string_uppercase(&data); +} + +// Shouldn't 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}"); } |
