[][src]Trait mruby::convert::RustBackedValue

pub trait RustBackedValue where
    Self: 'static + Sized
{ unsafe fn try_into_ruby(
        self,
        interp: &Mrb,
        slf: Option<mrb_value>
    ) -> Result<Value, MrbError> { ... }
unsafe fn try_from_ruby(
        interp: &Mrb,
        slf: &Value
    ) -> Result<Rc<RefCell<Self>>, MrbError> { ... }
fn new_obj_args(&self, interp: &Mrb) -> Vec<mrb_value> { ... } }

Provides converters to and from Value with ruby type of Ruby::Data.

This trait provides default implementations of try_into_ruby and try_from_ruby.

The 'static type bound comes from the class spec registry on State.

Warning: Self must be allocated on the heap. If Self is not heap allocated, malloc will fail when attempting to free the generated Ruby objects.

Provided methods

unsafe fn try_into_ruby(
    self,
    interp: &Mrb,
    slf: Option<mrb_value>
) -> Result<Value, MrbError>

Try to convert a Rust object into a Value.

Inject the data pointer into slf if it is provided, otherwise call sys::mrb_obj_new to get a new instance of the class associated with Self.

To store self in a sys::mrb_value, this function wraps self in an Rc<RefCell<_>>.

unsafe fn try_from_ruby(
    interp: &Mrb,
    slf: &Value
) -> Result<Rc<RefCell<Self>>, MrbError>

Extract the Rust object from the Value if the Value is backed by Self.

Extract the data pointer from slf and return an Rc<RefCell<_>> containing the Rust object.

This function sanity checks to make sure that Value is a Ruby::Data and that the RClass * of the spec matches the Value.

fn new_obj_args(&self, interp: &Mrb) -> Vec<mrb_value>

Return arguments to new when creating a sys::mrb_value.

This default implementation returns an empty Vec of arguments.

Implementations should override this method if they need to supply arguments to initialize the Ruby class.

Loading content...

Implementations on Foreign Types

impl<T> RustBackedValue for Box<T> where
    T: RustBackedValue
[src]

Loading content...

Implementors

impl RustBackedValue for MatchData[src]

impl RustBackedValue for Regexp[src]

Loading content...