mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-05 01:33:30 +02:00
Remove move_semantics4, add rest of move_semantics solutions
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user