4 ms·
Slices in Rust are actually kinda similar to VLAs in C99, but usable in places other than aggregates, and use an additional word in pointers to them for the len
by jessa0 6y ago
Slices in Rust are actually kinda similar to VLAs in C99, but usable in places other than aggregates, and use an additional word in pointers to them for the length, as a safety mechanism. You can even use slices as the last member of a struct, like VLAs, though they're not very ergonomic currently (you can only obtain references to them, as well as Boxes containing them, using "unsizing" coercion):
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=cf12a502a25d674f0f376af383af62a3 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- jessa0 6y agoOk, turns out I was mixing up "flexible array member" with "variable-length array". Slices can be used on the stack like a VLA as well, though, with the unstable "unsized_locals" feature. This feature is controversial, however, because of the risk of unintentional stack blowup..