I'm working with a set of a few dozen enums that are all either 1, 4, or 8 values of T = f64 (maybe f32), and the single value variant is by far the most common. During setup I'll use an ordinary mutable Vec of enums to be able to add/remove/configure everything. Then, perhaps via an Into method, I'd like to create the immutable layout for use as a reference for parallel runtimes. Would something like that be possible based on the following?
pub struct DenseGroup<T: Sized, const N: usize, const S: usize> {
storage: [MaybeUninit<u8>; S],
pointers: [Option<NonNull<??>>; N],
initialized: usize,
}
Basically I'd like bumpalo or arena-style allocation, but with a conceptually "fixed" memory layout that is effectively runtime assigned using compile-time-validated checks. I have zero desire to see this as an external crate, as I'm pretty sure it's a minefield of uninit, drop, and bounds concerns, plus many more I'm sure I haven't thought of. But, I think it could be very useful as an unsafe and internal only struct.
The other concern I have is: how to unify the pointers' type? I really just want a fixed block of memory containing a fixed amount of variously-sized objects that I can iterate, map, and reduce over. That leads me to think it will need to be dyn Trait, but then it's unsized... Is that the Achilles heel here? Or would it just require use of a custom Box? But aren't boxes just pointers?
Nevertheless, if that doesn't torpedo this, then the process to go from setup to run is just - count the number of items (N) and sum the size_of all items (S) to be able to initialize the container. Then immediately push (copy) all items, shadow itself into an immutable instance, and ... step 3 profit?