4 ms·
> A common workaround is to put items in a Vec and pass indices around. This doesn't fix the problem. It just escapes lifetime management. Lifetime errors then
by saurik 2y ago
> A common workaround is to put items in a Vec and pass indices around. This doesn't fix the problem. It just escapes lifetime management. Lifetime errors then turn into index errors, referencing the wrong object.
That people seriously are doing this is so depressing... if you build what amounts to a VM inside of a safe language so you can do unsafe things, you have at best undermined the point of the safe language and at worse disproved the safe language is sufficient.
- Animats 2y agoThat's a good way to put it. I'll keep that in mind when trying to convince the Rust devs.
- edflsafoiewq 2y agoThis is a common pattern everywhere, not just in Rust. Indices, unlike pointers to elements, survive a vector reallocation or serialization to disk. IDs are used to reference items in an SQL database, etc.
- imtringued 2y agoI hope you realize that index buffers are an industry standard in graphics APIs.
- Animats 2y agoVertex index buffers are not usually updated dynamically. Vulkan bindless descriptor tables are updated dynamically, and do have pointers to memory addresses. Those require a slot allocator and a deferred, interlocked deletion system to prevent deleting something from underneath a renderer. Not fun. I've been working on that.
- saurik 2y agoI do. I am not saying they are not useful... I am saying they are not safe. In a world where you care about the safety guarantees of Rust, you'd take an API that insists on manual index management and you would build an abstraction over it that allowed the compiler to prove its correctness using a proof system of some form, maybe borrow checking, or maybe something much more sophisticated.