#[repr(C)]pub struct RTypedData {
pub basic: RBasic,
pub type_: *const rb_data_type_t,
pub typed_flag: VALUE,
pub data: *mut c_void,
}Expand description
“Typed” user data. By using this, extension libraries can wrap a C struct
to make it visible from Ruby. For instance if you have a struct timeval,
and you want users to use it,
static inline const [`rb_data_type_t`] timeval_type = {
// Note that unspecified fields are 0-filled by default.
.wrap_struct_name = "timeval",
.function = {
.dmark = nullptr, // no need to mark
.dfree = RUBY_TYPED_DEFAULT_FREE, // use ruby_xfree()
.dsize = [](auto) {
return sizeof(struct timeval);
},
},
};
extern "C" void
Init_timeval(void)
{
auto klass = [`rb_define_class`]"YourName", [`rb_cObject`];
[`rb_define_alloc_func`]klass, [](auto klass) {
struct timeval *t;
auto ret = TypedData_Make_Struct(
klass, struct timeval, &timeval_type, t);
if (auto i = gettimeofday(t, nullptr); i == -1) {
[`rb_sys_fail`]"gettimeofday(3)");
}
else {
return ret;
}
});
}Generated by rb-sys for Ruby mri-x86_64-linux-gnu-3.2.3
Fields§
§basic: RBasic§The part that all ruby objects have in common.
Generated by rb-sys for Ruby mri-x86_64-linux-gnu-3.2.3
type_: *const rb_data_type_t§This field stores various information about how Ruby should handle a data. This roughly resembles a Ruby level class (apart from method definition etc.)
Generated by rb-sys for Ruby mri-x86_64-linux-gnu-3.2.3
typed_flag: VALUEThis has to be always 1.
@internal
§Why, then, this is not a const ::VALUE?
Generated by rb-sys for Ruby mri-x86_64-linux-gnu-3.2.3
data: *mut c_void§Pointer to the actual C level struct that you want to wrap.
Generated by rb-sys for Ruby mri-x86_64-linux-gnu-3.2.3
Trait Implementations§
Source§impl Clone for RTypedData
impl Clone for RTypedData
Source§fn clone(&self) -> RTypedData
fn clone(&self) -> RTypedData
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RTypedData
impl Debug for RTypedData
Source§impl PartialEq for RTypedData
impl PartialEq for RTypedData
impl Copy for RTypedData
impl Eq for RTypedData
impl StructuralPartialEq for RTypedData
Auto Trait Implementations§
impl Freeze for RTypedData
impl RefUnwindSafe for RTypedData
impl !Send for RTypedData
impl !Sync for RTypedData
impl Unpin for RTypedData
impl UnwindSafe for RTypedData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more