Skip to content

Trying to understand the safety of using references in Rhai #961

Answered by schungx
gitstashpop asked this question in Q&A
Discussion options

You must be logged in to vote
dir_state: &Rc<DirState>,

Rhai does not support references as parameters. All parameters must be Clone and passed in. Except for the first parameter, which may be &mut.

https://rhai.rs/book/rust/methods.html#admonition-no-support-for-references

Are there any issues with passing a reference to dir_state to my Rust fn (open_helper) from open()?

This is absolutely OK. The Rust compiler does not stop you, so it is OK. Your function parameters are all Clone and passed in, inside you can do whatever you want and no references can ever be passed outside of the function.

Rhai doesn't panic by itself (other than documented) so you can do anything you want with it, as long as it is not unsafe and…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@gitstashpop
Comment options

Answer selected by gitstashpop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants