Re:Variable Length Arrays are problematic
by SV_BubbleTime on Tuesday July 06, 2021 @12:41PM
(#27750926)
>You can put an unsized type at the end of a struct, resulting in an unsized struct. Using a slice as the last member is equivalent to a flexible array member in C.
News to me! I figured it was inherently a little "unsafe" and Rust's thing in mem safety. Good to know!
>Unfortunately they're barely usable in the current state, since there is no good way to construct such a struct.
Ok, well, now that's just bizarre, but I assume there is a good reason. I'll get on Rust when it's "official" somewhere for embedded. Until then, a strange and mystical shadow in the forest for me.
Rust has unsized types, like slices. Such types can't be passed by value and pointers to such types consist of two words (address and length for slices). You can put an unsized type at the end of a struct, resulting in an unsized struct. Using a slice as the last member is equivalent to a flexible array member in C.
Unfortunately they're barely usable in the current state, since there is no good way to construct such a struct.