rustlings icon indicating copy to clipboard operation
rustlings copied to clipboard

exercises/05_vecs/vecs1.rs: TODO clarification

Open hikojlu opened this issue 1 year ago • 5 comments

exercises/05_vecs/vecs1.rs:

let a = [10, 20, 30, 40];
// TODO: Create a vector called `v` which contains the exact same elements as in the array `a`
// Use the vector macro

vec! macro can only be used like this: vec![10, 20, 30, 40]. Is it intended to be like this? I guess, it would make more sense to use Vec::from(a)

hikojlu avatar Jan 07 '25 21:01 hikojlu

I think what the exercise intended was vec![10, 20, 30, 40]

Although it wouldn't make much of a difference if you use Vec::from or the vec! macro

frroossst avatar Jan 13 '25 16:01 frroossst

The alternative which references the a array and per the instructions uses the vec! macro:

let v = vec![a[0], a[1], a[2], a[3]];

jyap808 avatar Feb 14 '25 23:02 jyap808

I think you try to overengineering this :) The exercise is not about reusing memory or about references, its just about using vec! macro, just it So to use vec![10, 20, 30, 40] is absolutely normal solution

temanmd avatar Feb 19 '25 12:02 temanmd

I think you try to overengineering this :) The exercise is not about reusing memory or about references, its just about using vec! macro, just it So to use vec![10, 20, 30, 40] is absolutely normal solution

Yes, but many people get confused by this exercise, so I will do something to make the intention clear.

mo8it avatar Feb 19 '25 14:02 mo8it

I think the wording "which contains the exact same elements as" heavily suggests that you're supposed to somehow tell Rust to reuse the existing array elements, which is what tripped me up since it felt like a sudden escalation of difficulty compared to the exercises before

niktss avatar Oct 06 '25 20:10 niktss