I’m trying to build a user interface in Rust.
I’d like to describe the state of the app as a struct and, like React, have a
render() function that would rerender the UI when the state changes. But I’d like to only render what has changed.
So I would have
state2, I’d like to get a diff. So far, I’ve been using https://github.com/Byron/treediff-rs that basically does a JSON diff between the structures and gives me back a list of changed properties as an array of strings.
In the render function, I would go through the diff, and compare the string with the field of my struct.
This is getting very cumbersome as everytime I add a field to my struct, I have to make sure to update my render functions. And if I make a mistake or forget something, it fails during the runtime, not at compile time, because I compare strings.
Would there be a smarter way of doing this?
Ideally, I would have an arbitrary struct, and a macro or something would generate a list of possible diff, as an enum, so a missing check would be noticed at compile time, not at runtime.
Also, maybe there is a better alternative to
treediff, something that doesn’t require serialization.