Function tvm_rt::function::register[][src]

pub fn register<F, I, O, S: Into<String>>(f: F, name: S) -> Result<()> where
    F: ToFunction<I, O>,
    F: Typed<I, O>, 
Expand description

Registers a Rust function with an arbitrary type signature in the TVM registry.

A function is convertible if and only if its arguments and return types are convertible to and from TVM values respectively.

Use register_override if control of overriding existing global TVM function is required, this function will panic if a function is already registered.

Example


fn sum(x: i64, y: i64, z: i64) -> i64 {
    x + y + z
}

register(sum, "mysum".to_owned()).unwrap();
let func = Function::get("mysum").unwrap();
let boxed_fn: Box<dyn Fn(i64, i64, i64) -> Result<i64>> = func.into();
let ret = boxed_fn(10, 20, 30).unwrap();
assert_eq!(ret, 60);