How to nicelly edit each field of a (very) big struct with nested structs ? #2329
Replies: 2 comments 1 reply
-
I think what you are looking for is for a way to not have to clone your bits of the struct all the time and just keep it in one place. |
Beta Was this translation helpful? Give feedback.
-
Yes, my first attempt to solve this problem was to use Edit: an example of a nested structure |
Beta Was this translation helpful? Give feedback.
-
Hello,
I'm working on a save editor for the Mass Effect trilogy and I use Yew as the user interface executed in a web view (with the wry crate).
I use serde to deserialize the save then the user can edit every value of the deserialized structure (that can be a value in a few levels of nested structures) then I use serde again to serialize the save.
The view is auto generated based of the content of the save and looks like this:
Until now my approach was to use
Rc<RefCell<T>>
in every fields in every structures and I used a macro to "rcize" these fields :becomes
then I clone the
Rc
of each field into the props of the corresponding component and use the inner mutability of theRefCell
to edit the value in theupdate
function.You can see an exemple of a components in the following example with :
https://github.com/KarlitosVII/trilogy-save-editor/blob/main/src/gui/components/check_box.rs
Using this approach works but it have a lot of downsides :
Rc
each time I need to use a value in a component.borrow()
,.borrow_mut()
and deref*
everywhereRc<RefCell<T>>
for every data of hundreds of kilobytes has a non negligible runtime costSo, here is my question: is there a better / nicer way to do the same but with less boilerplate, less hacky tricks, cheaper runtime cost and/or with more readable code ?
Thanks in advance !
Beta Was this translation helpful? Give feedback.
All reactions