mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-03 16:53:30 +02:00
Redesign vec1 to avoid confusing array literal
Learners were sometimes confused by the literal array. Their assumption was that they are supposed to convert the array to a vector. Duplicating the literal elements was not an intuitive solution. This redesign avoids putting an identical array literal near the place where learners are supposed to use the vec! macro.
This commit is contained in:
@@ -1,10 +1,5 @@
|
||||
fn array_and_vec() -> ([i32; 4], Vec<i32>) {
|
||||
let a = [10, 20, 30, 40]; // Array
|
||||
|
||||
// Used the `vec!` macro.
|
||||
let v = vec![10, 20, 30, 40];
|
||||
|
||||
(a, v)
|
||||
fn elems_to_vec(a: i32, b: i32, c: i32) -> Vec<i32> {
|
||||
vec![a, b, c]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -16,8 +11,11 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_array_and_vec_similarity() {
|
||||
let (a, v) = array_and_vec();
|
||||
assert_eq!(a, *v);
|
||||
fn test_elems_to_vec() {
|
||||
let (a, b, c) = (2, 7, 12);
|
||||
let v = elems_to_vec(a, b, c);
|
||||
assert_eq!(v[0], a);
|
||||
assert_eq!(v[1], b);
|
||||
assert_eq!(v[2], c);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user