1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2025-12-01 22:51:45 +02:00

move_semantics2 solution

This commit is contained in:
mo8it
2024-06-21 17:02:50 +02:00
parent 946c29679e
commit 68142aff7f
3 changed files with 35 additions and 14 deletions

View File

@@ -1,5 +1,3 @@
// Make the test pass by finding a way to keep both Vecs separate!
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
let mut vec = vec;
@@ -16,13 +14,15 @@ fn main() {
mod tests {
use super::*;
// TODO: Make both vectors `vec0` and `vec1` accessible at the same time to
// fix the compiler error in the test.
#[test]
fn move_semantics2() {
let vec0 = vec![22, 44, 66];
let vec1 = fill_vec(vec0);
assert_eq!(vec0, vec![22, 44, 66]);
assert_eq!(vec1, vec![22, 44, 66, 88]);
assert_eq!(vec0, [22, 44, 66]);
assert_eq!(vec1, [22, 44, 66, 88]);
}
}