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 objecttag- Tag identifying the requested trait interface
§Returns
Some(&V)if the object implements the traitNoneif the object does not implement the trait
§Safety
sexpmust be a valid SEXPVmust be the correct view type fortag- 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");
}