pub trait InnerValue {
type Value: ReprValue;
// Required method
fn get_inner_with(self, ruby: &Ruby) -> Self::Value;
}
Expand description
Helper trait for Ruby::get_inner
.
This trait allows for Ruby::get_inner
to get the inner value of both
Opaque
and Lazy
.
Required Associated Types§
Required Methods§
Sourcefn get_inner_with(self, ruby: &Ruby) -> Self::Value
fn get_inner_with(self, ruby: &Ruby) -> Self::Value
Get the inner value from self
.
ruby
acts as a token proving this is called from a Ruby thread and
thus it is safe to return the inner value.
§Examples
use magnus::{
rb_assert,
value::{InnerValue, Opaque},
Ruby,
};
let ruby = Ruby::get().unwrap();
let opaque_str = Opaque::from(ruby.str_new("example"));
// send to another Ruby thread
let ruby = Ruby::get().unwrap(); // errors on non-Ruby thread
let str = opaque_str.get_inner_with(&ruby);
rb_assert!(ruby, r#"str == "example""#, str);
use magnus::{
rb_assert,
value::{InnerValue, Lazy},
RString, Ruby,
};
static STATIC_STR: Lazy<RString> = Lazy::new(|ruby| ruby.str_new("example"));
let ruby = Ruby::get().unwrap(); // errors if Ruby not initialised
let str = STATIC_STR.get_inner_with(&ruby);
rb_assert!(ruby, r#"str == "example""#, str);