I’m trying to create a global registry of types and associated functionality generated on program startup. For my use case, this sort of registry has a lot of advantages over maintaining a function with some long list of calls (I’ve tried both ways in the past with C).
In C, I’ve done this with attribute((constructor)) for the desired types which would populate some hash table with the required metadata, and that worked fairly well. In Rust, I can use the ctor crate, but from the documentation documentation that doesn’t appear to play very well with using anything from stdlib. I don’t want to play with fire and use the allocator beforehand if it may not be in a good state. Instead, I keep a massive static array and write constructor function pointers into it so I can later at runtime generate the actual data.
Is there a better way to do this in rust? Can I assume that jemalloc has been properly initialized when static constructors run? This current method is opaque enough where I have to wrap it with a fairly gnarly macro to keep it sensible to users