Skip to main content

mx_query

Function mx_query 

Source
pub unsafe fn mx_query(sexp: SEXP, tag: mx_tag) -> *const c_void
Expand description

Query an object for an interface vtable by tag.

Looks up whether the object implements the trait identified by tag, and returns a pointer to the vtable if so.

§Arguments

  • sexp - R external pointer wrapping an erased object
  • tag - Tag identifying the requested trait interface

§Returns

  • Non-null pointer to the trait’s vtable if implemented
  • Null pointer if:
    • sexp is not a valid erased object
    • The object does not implement the requested trait

§Safety

  • sexp must be a valid SEXP
  • Must be called on R’s main thread
  • The returned pointer must be cast to the correct vtable type

§Example

let vtable = unsafe { mx_query(obj, TAG_FOO) };
if !vtable.is_null() {
    let foo_vtable = vtable.cast::<FooVTable>();
    // Call method through vtable...
}