News for hackers. Stuff that matters.
Re:Zig's Curious Multi-Sequence for Loops by alpaca128 on Tuesday February 28, 2023 @05:40AM (#34967845)
The Rust docs are very clear that initializing an empty vector does not cause an allocation and is thus equivalent to using `Vec::with_capacity(0)`. The same applies to strings because strings are vectors of bytes with additional methods.

Whether a clearly visible `vec.push(x)` call is silent to you depends on your viewpoint. I'd say it's explicitly recognizeable as potential allocation, it has to be when pushing to a dynamic structure of arbitrary size - but I also understand how this can be seen differently. This is, I think, where Rust and Zig differ a lot. Rust makes most things explicit but still allows things like this or macros, Zig tries to avoid even that.

There are no comments on this comment yet.