Also it's not possible to register both getter and setter with register_get_set because one returns a String and the other expects a &str.
error[E0631]: type mismatch in function arguments
--> rhai_\src\main.rs:32:57
|
16 | fn set_field(&mut self, new_val: &str) {
| -------------------------------------- found signature of `for<'r, 's> fn(&'r mut TestStruct, &'s str) -> _`
...
32 | .register_get_set("xyz", TestStruct::get_field, TestStruct::set_field)
| ---------------- ^^^^^^^^^^^^^^^^^^^^^ expected signature of `for<'r> fn(&'r mut TestStruct, String) -> _`
| |
| required by a bound introduced by this call
|
note: required by a bound in `rhai::api::register::<impl Engine>::register_get_set`
--> C:\Users\_\.cargo\registry\src\github.com-1ecc6299db9ec823\rhai-1.8.0\src\api\register.rs:555:22
|
555 | set_fn: impl Fn(&mut T, V) + SendSync + 'static,
| ^^^^^^^^^^^^^ required by this bound in `rhai::api::register::<impl Engine>::register_get_set`
For more information about this error, try `rustc --explain E0631`.
The following example doesn't compile.
https://github.com/rhaiscript/book/blob/dc74fc9f6f3d74e69e6615b113a3fdd801b0329f/src/rust/getters-setters.md?plain=1#L63-L103
In
new
.to_string()
is missingAlso it's not possible to register both getter and setter with
register_get_set
because one returns aString
and the other expects a&str
.