[][src]Trait artichoke_backend::convert::RustBackedValue

pub trait RustBackedValue where
    Self: 'static + Sized
{ fn ruby_type_name() -> &'static str; unsafe fn try_into_ruby(
        self,
        interp: &Artichoke,
        slf: Option<mrb_value>
    ) -> Result<Value, ArtichokeError> { ... }
unsafe fn try_from_ruby(
        interp: &Artichoke,
        slf: &Value
    ) -> Result<Rc<RefCell<Self>>, ArtichokeError> { ... } }

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.

Required methods

fn ruby_type_name() -> &'static str

Class or module name of this data type.

Loading content...

Provided methods

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

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: &Artichoke,
    slf: &Value
) -> Result<Rc<RefCell<Self>>, ArtichokeError>

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].

Loading content...

Implementations on Foreign Types

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

Loading content...

Implementors

impl RustBackedValue for Array[src]

impl RustBackedValue for Environ[src]

impl RustBackedValue for MatchData[src]

impl RustBackedValue for Random[src]

impl RustBackedValue for Regexp[src]

Loading content...