#[repr(transparent)]pub struct RStruct(_);
Expand description
Implementations
sourceimpl RStruct
impl RStruct
sourcepub fn from_value(val: Value) -> Option<Self>
pub fn from_value(val: Value) -> Option<Self>
Return Some(RStruct)
if val
is a RStruct
, None
otherwise.
sourcepub fn get<T>(self, index: usize) -> Result<T, Error>where
T: TryConvert,
pub fn get<T>(self, index: usize) -> Result<T, Error>where
T: TryConvert,
Return the value for the member at index
, where members are ordered
as per the member names when the struct class was defined.
sourcepub fn aref<T, U>(self, index: T) -> Result<U, Error>where
T: Into<Value>,
U: TryConvert,
pub fn aref<T, U>(self, index: T) -> Result<U, Error>where
T: Into<Value>,
U: TryConvert,
Return the value for the member at index
.
index
may be an integer, string, or Symbol
.
sourcepub fn aset<T, U>(self, index: T, val: U) -> Result<(), Error>where
T: Into<Value>,
U: Into<Value>,
pub fn aset<T, U>(self, index: T, val: U) -> Result<(), Error>where
T: Into<Value>,
U: Into<Value>,
Return the value for the member at index
.
index
may be an integer, string, or Symbol
.
Methods from Deref<Target = Value>
sourcepub unsafe fn to_s(&self) -> Result<Cow<'_, str>, Error>
pub unsafe fn to_s(&self) -> Result<Cow<'_, str>, Error>
Convert self
to a Rust string.
Safety
This may return a direct view of memory owned and managed by Ruby. Ruby may modify or free the memory backing the returned str, the caller must ensure this does not happen.
This can be used safely by immediately calling
into_owned
on the return value.
Examples
use magnus::{eval, QTRUE};
let value = QTRUE;
// safe as we neve give Ruby a chance to free the string.
let s = unsafe { value.to_s() }.unwrap().into_owned();
assert_eq!(s, "true");
sourcepub unsafe fn classname(&self) -> Cow<'_, str>
pub unsafe fn classname(&self) -> Cow<'_, str>
Return the name of self
’s class.
Safety
Ruby may modify or free the memory backing the returned str, the caller must ensure this does not happen.
This can be used safely by immediately calling
into_owned
on the return value.
Examples
use magnus::{eval, RHash};
let value = RHash::new();
// safe as we neve give Ruby a chance to free the string.
let s = unsafe { value.classname() }.into_owned();
assert_eq!(s, "Hash");
Trait Implementations
sourceimpl Object for RStruct
impl Object for RStruct
sourcefn define_singleton_method<M>(self, name: &str, func: M) -> Result<(), Error>where
M: Method,
fn define_singleton_method<M>(self, name: &str, func: M) -> Result<(), Error>where
M: Method,
self
’s scope. Read moresourcefn ivar_set<T, U>(self, name: T, value: U) -> Result<(), Error>where
T: Into<Id>,
U: Into<Value>,
fn ivar_set<T, U>(self, name: T, value: U) -> Result<(), Error>where
T: Into<Id>,
U: Into<Value>,
sourceimpl TryConvert for RStruct
impl TryConvert for RStruct
sourcefn try_convert(val: Value) -> Result<Self, Error>
fn try_convert(val: Value) -> Result<Self, Error>
val
into Self
.