What is the best data structure for a dynamic object system?

⚓ Rust    📅 2026-03-17    👤 surdeus    👁️ 3      

surdeus

Hello,
I am going to start working on a user interface framework, and my current plan is to have it based on a tree of objects. Objects can have any number of properties of any type, or at least a wide range of types, and in addition to storing values, properties can contain constraints which are functions that take values from other properties, either properties of the current object, child objects, or the parent object, and returns a calculated value. Every time a referenced field changes, the constraint function should be called to update the value. Also inheritance should be supported (prototype based), so that you can create an object using another object as its prototype or more than one, and the new object will have all the properties of its prototypes and their values, but unless the properties of the new object are explicitly set, when the prototype properties change the new object will also change. I need new properties to be able to be added at runtime, because I want to implement a scripting language (probably Scheme) where you can customize everything and develop new applications by creating objects and properties and linking them, and it would be nice to support loading plugins in other languages that can create and manipulate objects in the same way, and perhaps eventually allow this to be done from another process over IPC so that all UI applications do not have to be within the same process. However, I want to use Rust because it has very high performance, there are Rust libraries I want to use for things like audio, GPU, etc, and I was thinking Rust's type system and memory system would give me more guarantees than implementing everything in a dynamic language. But what data structures should I use for this kind of object system? I could create a bunch of HashMaps with strings as keys, but that sounds like it would have bad performance especially compared to Rust trait objects. Also probably for constraints and inheritance to work, I need everything wrapped in something like Arc so that everything can be referenced and modified from multiple places. Would Rust even be the best fit for this if I lose the compile-time guarantees the type system provides by having objects be dynamic and their properties not being guaranteed at compile time, and if I end up using Arcs for everything moving reference counting from the compiler to the runtime level?

1 post - 1 participant

Read full topic

🏷️ Rust_feed