Skip to main content

RTypedData

Struct RTypedData 

Source
#[repr(C)]
pub struct RTypedData { pub basic: RBasic, pub type_: *const rb_data_type_t, pub typed_flag: VALUE, pub data: *mut c_void, }
👎Deprecated:

To improve API stability with ruby-head, direct usage of Ruby internal structs has been deprecated. To migrate, please replace the usage of this internal struct with its counterpart in the rb_sys::stable module. For example, instead of use rb_sys::rb_sys__Opaque__ExampleStruct;, use use rb_sys::stable::ExampleStruct;. If you need to access the internals of these items, you can use the provided rb-sys::macros instead.

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
👎Deprecated:

To improve API stability with ruby-head, direct usage of Ruby internal structs has been deprecated. To migrate, please replace the usage of this internal struct with its counterpart in the rb_sys::stable module. For example, instead of use rb_sys::rb_sys__Opaque__ExampleStruct;, use use rb_sys::stable::ExampleStruct;. If you need to access the internals of these items, you can use the provided rb-sys::macros instead.

§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
👎Deprecated:

To improve API stability with ruby-head, direct usage of Ruby internal structs has been deprecated. To migrate, please replace the usage of this internal struct with its counterpart in the rb_sys::stable module. For example, instead of use rb_sys::rb_sys__Opaque__ExampleStruct;, use use rb_sys::stable::ExampleStruct;. If you need to access the internals of these items, you can use the provided rb-sys::macros instead.

§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: VALUE
👎Deprecated:

To improve API stability with ruby-head, direct usage of Ruby internal structs has been deprecated. To migrate, please replace the usage of this internal struct with its counterpart in the rb_sys::stable module. For example, instead of use rb_sys::rb_sys__Opaque__ExampleStruct;, use use rb_sys::stable::ExampleStruct;. If you need to access the internals of these items, you can use the provided rb-sys::macros instead.

This 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
👎Deprecated:

To improve API stability with ruby-head, direct usage of Ruby internal structs has been deprecated. To migrate, please replace the usage of this internal struct with its counterpart in the rb_sys::stable module. For example, instead of use rb_sys::rb_sys__Opaque__ExampleStruct;, use use rb_sys::stable::ExampleStruct;. If you need to access the internals of these items, you can use the provided rb-sys::macros instead.

§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

Source§

fn clone(&self) -> RTypedData

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for RTypedData

Source§

impl Debug for RTypedData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for RTypedData

Source§

impl PartialEq for RTypedData

Source§

fn eq(&self, other: &RTypedData) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RTypedData

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.