Function magnus::embed::init

source ·
pub unsafe fn init() -> Cleanup
Available on crate feature embed only.
Expand description

Initialises the Ruby VM.

See also Ruby::init and setup.

Calling this function is only required when embedding Ruby in Rust. It is not required when embedding Rust in Ruby, e.g. in a Ruby Gem.

§Safety

Must be called in main(), or at least a function higher up the stack than any code calling Ruby. Must not drop Cleanup until the very end of the process, after all Ruby execution has finished. Do not use Ruby values after Cleanup has been dropped.

§Panics

Panics if this, setup, or Ruby::init are collectively called more than once.

§Examples

let ruby = unsafe { magnus::embed::init() };
let result: i64 = ruby.eval("2 + 2").unwrap();
assert_eq!(result, 4);