Prevent access chain updates? #1103
Replies: 1 comment 2 replies
-
|
I don't understand. You mean a getters chain? And you set it at the end? In that case I can't see how you avoid having to set the values back... Because Rhai would not know that you don't need the new value set back into it. Or to use a temp variable as you suggest. Unless you can get a reference to the final value at the end of the chain. That's essentially what Rhai does to arrays and maps but that's a built in type. Since you say the sets are expensive, I suppose that means you have a deep tree of such pointers with arrays and maps and stuff that are excessively cloned when you set even one property. You can avoid that by making your mutation a method instead of a setter, but that would make the API less ergonomic. Another alternative is to map your type into Rhai types itself. In fact, any reasonable Rust type can be turned into a Rhai map and array structure that handles such chained updates elegantly. If all you have is a huge structure of pointers to the actual data, I'd suggest you model that directly with Rhai itself. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have rust types that are essentially pointers, which are registered and used in rhai scripts. These types have methods and setters that modify state elsewhere in rust-land, but the pointer value itself remains unchanged. Even when these setters and methods are marked pure, access chaining still propagates unneeded sets. In my case, these sets are relatively expensive. I would like to avoid these without requiring users to always assign the pointer to a variable before calling the setter/method. Is this currently possible?
Beta Was this translation helpful? Give feedback.
All reactions