Closed curldivergence closed 3 years ago
https://rhai.rs/book/rust/print-custom.html
This should do it.
Essentially, you define to_string
for your custom type.
Got it, thank you!
On a semi-related note (not to spam with another issue) - do I understand correctly that to be able to index a Vec<T>
from Rhai I also need to register a custom function via register_indexer_get
?
On a semi-related note (not to spam with another issue) - do I understand correctly that to be able to index a
Vec<T>
from Rhai I also need to register a custom function viaregister_indexer_get
?
That i s most correct. I'd suggest just registering both a getter and a setter. Remember to bounds-check (meaning you'd need fallible functions). There is even a convenient ErrorArrayBounds
error type you can use.
I see, thanks a lot for help :)
Hello. I have a Rust function that returns a
HashMap<String, ObjectID>
(ObjectID
is my newtype around u64 that implements bothDisplay
andDebug
). But unfortunately when I'm trying to print this object from a Rhai script like this:I'm getting
in my logs instead of the
HashMap
's contents :( So my question is if there is any way to get the actual map records printed without making a dedicated function for that? UsingDebug
instead ofDisplay
would work for me, too.Thanks!