Remo Senekowitsch 97a723508c
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.
2026-05-14 16:19:53 +02:00

22 lines
388 B
Rust

fn elems_to_vec(a: i32, b: i32, c: i32) -> Vec<i32> {
vec![a, b, c]
}
fn main() {
// You can optionally experiment here.
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
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);
}
}