I have read a lot about Rust lately, but I'm still just starting to oxidize. My brain retains most of its C / C ++ reflexes, so forgive me if this question does not matter due to how everything is done in Rust.
Is it possible at all (preferably?) To allocate a block of arbitrary size on the heap, and then compare the data structure above it with bindings that have smaller pieces of memory?
Using C99, you can write this:
typedef unsigned char BYTE; typedef struct { size_t size; BYTE payload[]; } flex;
Flexible length arrays can be useful, for example. when implementing memory pools with chunks of variable size or when allocating memory on a heap dedicated to threading. A data structure requiring size is known only at runtime, is allocated in an "atomic" way, and its elements are packed adjacent to each other.
I am wondering if a similar Rust implementation is possible (without unsafe constructs), and if so, how it looks. Maybe the compiler can output some information using the lifetime specifiers in the definition of struct ?
source share