pub struct TypeAttrDef<T: ObjectCore> { /* private fields */ }Expand description
Registers type attributes of the object type T, each as soon as
set_attr names it, for every language to read with
TypeAttrColumn.
As in C++, attributes register during static initialization, such as in a
static_init_block!, before other threads
read them: registrations from Rust lock each other out, but readers take
no lock.
§Examples
use tvm_ffi::reflection::TypeAttrDef;
use tvm_ffi::reflection::TypeAttrColumn;
use tvm_ffi::{rs_object, Object, ObjectCore};
#[rs_object(type_key = "my_ext.MyPair")]
pub struct MyPairObj {
base_: Object,
}
TypeAttrDef::<MyPairObj>::new().set_attr("my_ext.arity", 2_i64)?;
let column = TypeAttrColumn::lookup("my_ext.arity").unwrap();
let arity: i64 = column.get(MyPairObj::type_index()).unwrap().try_into()?;
assert_eq!(arity, 2);Implementations§
Source§impl<T: ObjectCore> TypeAttrDef<T>
impl<T: ObjectCore> TypeAttrDef<T>
Sourcepub fn set_attr(
self,
name: &str,
value: impl Into<Any> + Send + Sync,
) -> Result<Self>
pub fn set_attr( self, name: &str, value: impl Into<Any> + Send + Sync, ) -> Result<Self>
Register the type attribute name of T.
§Arguments
name- The name of the attribute.value- The value of the attribute,Send + Syncsince every thread reads it.
§Returns
The builder, for the next attribute.
§Errors
Returns an error if T already has the attribute name, or a
TypeError if value is an opaque pointer: register a native hook
with set_native_fn_attr.
Sourcepub unsafe fn set_native_fn_attr<Args, R>(
self,
name: &str,
f: NativeFunction<Args, R>,
) -> Result<Self>
pub unsafe fn set_native_fn_attr<Args, R>( self, name: &str, f: NativeFunction<Args, R>, ) -> Result<Self>
Register the native hook f as the type attribute name of T.
§Arguments
name- The name of the attribute.f- The hook.
§Returns
The builder, for the next attribute.
§Errors
Returns an error if T already has the attribute name.
§Safety
Every caller of the column name calls its hooks with exactly Args
and reads R: a native caller calls the function pointer unchecked.