Remove move_semantics4, add rest of move_semantics solutions

This commit is contained in:
mo8it
2024-06-21 18:14:19 +02:00
parent fd558065c7
commit e4dbbbf5f5
7 changed files with 73 additions and 84 deletions
+17 -16
View File
@@ -1,21 +1,22 @@
// Make me compile only by reordering the lines in the test, but without adding,
// changing or removing any of them.
// TODO: Fix the compiler erros. Don't change anything except adding or removing
// references (the character `&`).
fn main() {
// You can optionally experiment here.
let data = "Rust is great!".to_string();
get_char(data);
string_uppercase(&data);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn move_semantics5() {
let mut x = 100;
let y = &mut x;
let z = &mut x;
*y += 100;
*z += 1000;
assert_eq!(x, 1200);
}
// 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}");
}