mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-06 10:49:19 +00:00
Refactor fill_vec function to take a mutable reference to vec
This commit is contained in:
parent
4fd794e942
commit
1c51ad049f
@ -5,22 +5,18 @@
|
|||||||
// Execute `rustlings hint move_semantics2` or use the `hint` watch subcommand
|
// Execute `rustlings hint move_semantics2` or use the `hint` watch subcommand
|
||||||
// for a hint.
|
// for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn main() {
|
fn main() {
|
||||||
let vec0 = vec![22, 44, 66];
|
let mut vec0 = vec![22, 44, 66];
|
||||||
|
|
||||||
let mut vec1 = fill_vec(vec0);
|
let vec1 = fill_vec(&mut vec0.clone());
|
||||||
|
|
||||||
assert_eq!(vec0, vec![22, 44, 66]);
|
assert_eq!(vec0, vec![22, 44, 66]);
|
||||||
assert_eq!(vec1, vec![22, 44, 66, 88]);
|
assert_eq!(vec1, vec![22, 44, 66, 88]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
fn fill_vec(vec: &mut Vec<i32>) -> Vec<i32> {
|
||||||
let mut vec = vec;
|
|
||||||
|
|
||||||
vec.push(88);
|
vec.push(88);
|
||||||
|
|
||||||
vec
|
vec.to_vec()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user