Skip to main content

mx_query_as

Function mx_query_as 

Source
pub unsafe fn mx_query_as<V>(sexp: SEXP, tag: mx_tag) -> Option<&'static V>
Expand description

Query an object for an interface and return a typed view.

Looks up tag in the object’s vtable registry and, if found, returns Some(&V) pointing to the data pointer + vtable pair for the trait.

§Type Parameters

  • V - The view type (e.g., FooView) containing data pointer and vtable

§Arguments

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

§Returns

  • Some(&V) if the object implements the trait
  • None if the object does not implement the trait

§Safety

  • sexp must be a valid SEXP
  • V must be the correct view type for tag
  • Must be called on R’s main thread

§Example

if let Some(view) = unsafe { mx_query_as::<FooView>(obj, TAG_FOO) } {
    let result = view.some_method(args);
} else {
    panic!("object does not implement Foo");
}