How would I implement a trait within an engine and change plugin function signature? #956
-
Hi, I'm very new to Rhai/Rust. ProblemI would like to implement a trait in my Engine declaration code, and not expose functions in Rhai scripts that take the trait as an argument. For example, the implementation would be I have a working example (which follows) without using Rhai plugin macros, but I was wondering if there is a better way to do this/something more idiomatic. It also seems like overriding each function that I implement this way with an implementation of the trait might not be the most scalable engine registration code. Thanks! CodeRhai crate
Engine creation code in a different crate
Call my scriptNotice that when my Rhai script is written, I do not need to provide the Policy implementation, which is my desired behavior my_fn("/tmp/hello.txt"); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Not very sure what you want to achieve... It seems to be working for you, correct? If your function differs from the implementation in number of parameters, then you must obviously provide the missing arguments somehow. In your example you capture it in a closure. This is very proper way to do things in Rust. They are different functions afterall... |
Beta Was this translation helpful? Give feedback.
-
@schungx I really liked the cleanliness of using the procedural macros to generate a Rhai plugin. I break that model with my working implementation. I was generally looking to see if what I have is ok based on Rust/Rhai best practices and it sounds like the answer is yes. Thank you! |
Beta Was this translation helpful? Give feedback.
Not very sure what you want to achieve... It seems to be working for you, correct?
If your function differs from the implementation in number of parameters, then you must obviously provide the missing arguments somehow. In your example you capture it in a closure.
This is very proper way to do things in Rust. They are different functions afterall...