summaryrefslogtreecommitdiff
path: root/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt
blob: ba234529a3e8c5aa4bb4996df081e2f0b7dc682a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
use magnus::{function, prelude::*, Error, Ruby};

fn hello(subject: String) -> String {
    format!("Hello from Rust, {subject}!")
}

#[magnus::init]
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(())
}