[rubygems/rubygems] update Magnus library in Rust extension gem template

https://github.com/rubygems/rubygems/commit/19a92a3367
This commit is contained in:
Mat Sadler 2023-07-28 21:19:04 -07:00 committed by git
parent 36023d5cb7
commit a3c0e9d90d
2 changed files with 5 additions and 5 deletions

View File

@ -12,4 +12,4 @@ publish = false
crate-type = ["cdylib"]
[dependencies]
magnus = { version = "0.4" }
magnus = { version = "0.6" }

View File

@ -1,12 +1,12 @@
use magnus::{define_module, function, prelude::*, Error};
use magnus::{function, prelude::*, Error, Ruby};
fn hello(subject: String) -> String {
format!("Hello from Rust, {}!", subject)
format!("Hello from Rust, {subject}!")
}
#[magnus::init]
fn init() -> Result<(), Error> {
let module = <%= config[:constant_array].map {|c| "define_module(#{c.dump})?"}.join(".") %>;
fn init(ruby: &Ruby) -> Result<(), Error> {
let module = ruby.<%= config[:constant_array].map {|c| "define_module(#{c.dump})?"}.join(".") %>;
module.define_singleton_method("hello", function!(hello, 1))?;
Ok(())
}