I have an existing C# application, but some parts of it are poor in performance for a number of reasons. I want to rewrite those parts in Rust and interact with my new native library using P/Invoke. However, the parts of my code that I'm wondering about are the parts that made use of INotifyPropertyChanged
or Observable<T>
.
For reference, INotifyPropertyChanged
is a pattern where the class that implements that interface (trait) will fire an event (property "y" on object x has changed) every time one of the class's properties is changed, regardless of what caused the change (the typical exception is for properties which affect each others' values, in order to avoid a stack overflow).
For my particular use case, I am trying to keep track of a tree structure that exists in my Rust code from C#. It would be ideal if these change notifications had a way of bubbling up to the root of the tree (i.e., if x.y[0].z
changes, then y[0]
fires an event, which is seen by x
, and x
fires an event).
Is there a recommended pattern for finding out when a property of an object is changed in Rust? For example, is there a way to know when a property of a struct is borrowed and fire a callback?
I've seen How can I implement the observer pattern in Rust?, but the accepted answer doesn't fully address what I'm wondering.