Rust 2019 Wish: Improve on Entity-management and Indexing (Slab, Specs, etc...)


Well this is a single technical wish. I’ve read many Rust 2019 posts so far, they’re great. But none of them mentioned the importance of this single item, so i made this single dedicated post for itself. This is the second most wanted thing of mine in Rust in 2019.(The most wanted one is async/await, of course).

I think so far it has been proved that entity/index-based object value management is quite fundamental in Rust. Basically everything that cannot be modelled as a direct “nesting” relationship(if they are, they can be modelled by lifetimes and borrow-checking easily) needs to be modelled this way.

So in this direction currently I can think of many crates (this list is not by any means complete, but only meant to offer only some concrete examples):

petgraph: Index-based graph management.
slab: Index-based homogeneity values management.
slotmap: Generation/Index-based homogeneity values management.
specs: Entity-based ECS system, mostly for games.
nitric: Upcoming entity-management library.
and many many more!

While these libraries are awesome, they’re community-maintained, which means their APIs might have not been discussed and audited to a level that’s parallel to libstd APIs; their discoverability and interoperability might not have be been pushed to a level that’s parallel to libstd types; their documentation might not have been as high qualitied as libstd types; and their future development might not have been as promising as libstd types.

So this makes me wonder if there’s gonna be some official effort to coordinate these projects in some way. (An “Entity-WG” or something people think appropriate) I think it’ll be great if people won’t need to put their efforts into inventing their own ID types and managing their belonging data in their own project next time. I think it’ll be great if more tutorials are written. I think it’ll be great if it can lay a solid foundation for solving farther problems likes managing GUI states, improving support for XML/HTML/other tree/graph style datatypes, and solving other domain problems down the road.



Note also id_arena and generational_arena crates.

It’s also interesting than in Rust analyzer I’ve just rolled my own arena crate because existing ones were not quite as simple as as needed.



I think of the first steps related to this problem is interop, ie shared vocabulary.

My hope is nitric can be that interop. From what I understand, specs can (is going to be?) built on top of it. Could petgraph be built on top of it? Maybe more of a stretch, but could salsa?

1 Like