mruby safe bindings for Rust
Rust Ruby C Shell
Clone or download

mrusty. mruby safe bindings for Rust

Build Status Coverage Status Cargo Crate

mrusty lets you:

  • run Ruby 1.9 files with a very restricted API (without having to install Ruby)
  • reflect Rust structs and enums in mruby and run them

It does all this in a safely neat way, while also bringing spec testing and a REPL to the table.



A very simple example of a Container struct which will be passed to mruby and which is perfectly callable.

// mrusty_class!
extern crate mrusty;

use mrusty::{Mruby, MrubyImpl};

let mruby = Mruby::new();

struct Cont {
    value: i32

// Cont should not flood the current namespace. We will add it with require.
mrusty_class!(Cont, "Container", {
    // Converts mruby types automatically & safely.
    def!("initialize", |v: i32| {
        Cont { value: v }

    // Converts slf to Cont.
    def!("value", |mruby, slf: (&Cont)| {

// Add file to the context, making it requirable.

// Add spec testing.
describe!(Cont, "
  context 'when containing 1' do
    it 'returns 1 when calling #value' do
      expect( eql 1

let result ="
  require 'cont'
").unwrap(); // Returns Value.

println!("{}", result.to_i32().unwrap()); // Prints "3".