When trying to design a UI engine in rust and exposing api to c++ logic, my current thinking would be separating the dom and program logic via a binding mechanism.
Pseudo code:
// in c style, but types are in c++ or rust for clear meaning (RwLock<T>* would be void* in the interface.)
extern "C" void bind_attr(widget* w, int idx, RwLock<T>* Pdata){xxxxx}
UI system in rust should be able to set the value, and c++ side should be able to read it. Synchronization is needed between UI thread and program logic thread, and a read-write lock seems appropriate for generic types (atomic for simple types? Is there binding available?).
RwLock<T>
is implemented by the rust standard library, and the object needs to be created on c++ side (likely on the struct that is responsible for this piece of logic). Also both sides need to agree on the layout of data, which seems impossible with RwLock<T>
in rust repr?
Is there a simple way of implementing the binding, or do I have to use a c++ implementation of read-write lock and create a binding in rust?