Skip to main content

cached_field_getter

Macro cached_field_getter 

Source
macro_rules! cached_field_getter {
    ($owner:ty, $name:literal) => { ... };
}
Expand description

Resolve a reflected field of the object type N once, and keep its getter for the process: a &'static FieldGetter<N>.

Each call site has its own cache, which later calls read without a lock. N must be a concrete type, not Self or a generic parameter. It panics, naming the field, if N has no such field. See also FieldGetter::of, which returns an error instead.

ยงExamples

use tvm_ffi::{cached_field_getter, rs_object, Object, ObjectArc};

#[rs_object(type_key = "my_ext.Point")]
pub struct PointObj {
    base_: Object,
    x: i64,
}

let point = ObjectArc::new(PointObj { base_: Object::new(), x: 3 });
let x: i64 = cached_field_getter!(PointObj, "x").get(&*point)?;
assert_eq!(x, 3);