[−][src]Trait artichoke_backend::convert::RustBackedValue
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.
Provided methods
unsafe fn try_into_ruby(
self,
interp: &Artichoke,
slf: Option<mrb_value>
) -> Result<Value, ArtichokeError>
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>
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
].
Implementations on Foreign Types
impl<T> RustBackedValue for Box<T> where
T: RustBackedValue,
[src]
T: RustBackedValue,