Struct mrusty::Module [] [src]

pub struct Module {
    // some fields omitted
}

A struct that wraps around an mruby Module.

Examples

let mruby = Mruby::new();

let module = mruby.def_module("Container");

assert_eq!(module.to_str(), "Container");

Methods

impl Module
[src]

fn include(&self, module: Module)

Includes a Module in a Module.

Examples

let mruby = Mruby::new();

mruby.run("
  module Increment
    def inc
      self + 1
    end
  end

  module Increment2; end
").unwrap();

let fixnum = mruby.get_class("Fixnum").unwrap();
let increment = mruby.get_module("Increment").unwrap();
let increment2 = mruby.get_module("Increment2").unwrap();

increment2.include(increment);
fixnum.include(increment2);

let result = mruby.run("1.inc").unwrap();

assert_eq!(result.to_i32().unwrap(), 2);

fn def_const(&self, name: &str, value: Value)

Defines constant with name name and value value on a Module.

Examples

let mruby = Mruby::new();

mruby.run("
  module Container; end
").unwrap();

let cont = mruby.get_module("Container").unwrap();

cont.def_const("ONE", mruby.fixnum(1));

let result = mruby.run("Container::ONE").unwrap();

assert_eq!(result.to_i32().unwrap(), 1);

fn to_str(&self) -> &str

Returns a &str with the mruby Module name.

Examples

let mruby = Mruby::new();

let module = mruby.def_module("Container");

assert_eq!(module.to_str(), "Container");

fn to_value(&self) -> Value

Casts Module to Value.

Examples

let mruby = Mruby::new();

let module = mruby.def_module("Container");
let value = module.to_value();

let name = value.call("to_s", vec![]).unwrap();

assert_eq!(name.to_str().unwrap(), "Container");

Trait Implementations

impl ClassLike for Module
[src]

fn class(&self) -> *const MrClass

impl Clone for Module
[src]

fn clone(&self) -> Module

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more

impl PartialEq<Module> for Module
[src]

fn eq(&self, other: &Module) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Rhs) -> bool
1.0.0

This method tests for !=.

impl Debug for Module
[src]

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.