I tried to implement it in Rust, but ran into a seemingly fundamental problem. Even with unsafe, Rust seems to have no way to read uninitialized memory without causing undefined behavior.
Is there a way to implement this trick in Rust (without undefined behavior)? If not, are there any upcoming proposals that would allow implementing this trick?
The primary benefit of the data structure is the O(1) clear operation. You still get that if you zero-initialize the memory when you first allocate it. So I'd just do that, it shouldn't have that much overhead over allocating non-initialized memory in most applications.
To date, that's true within the Rust abstract machine AFAIU. Some want the ability, others actively don't. You can search for LLVM freeze for more discussion. (Sadly you will have to wade through many false hits regarding the Freeze trait, which is something else.)
You can presumably roundtrip through something outside the abstract machine, like FFI. But I'm afraid I don't have an example handy.