pub struct EsFunction { /* private fields */ }
Expand description

used to create a new Function

Example

    

Implementations

create a new Function based on a method

create a new Function based on a method

Example
use quickjs_runtime::esvalue::{EsFunction, EsValueConvertible, ES_NULL, EsValueFacade};
use quickjs_runtime::builder::QuickJsRuntimeBuilder;
use hirofa_utils::js_utils::Script;
async fn do_something(args: Vec<EsValueFacade>) -> Result<EsValueFacade, String> {
    Ok(123.to_es_value_facade())
}
let func_esvf = EsFunction::new_async("my_callback", do_something).to_es_value_facade();
let rt = QuickJsRuntimeBuilder::new().build();
rt.eval_sync(Script::new("new_async.es", "this.test_func = function(cb){return cb();};")).ok().expect("func invo failed");
let func_res = rt.call_function_sync(vec![], "test_func", vec![func_esvf]).ok().expect("func invo failed2");
let ret = func_res.get_promise_result_sync().ok().expect("do_something returned err");
assert_eq!(ret.get_i32(), 123);

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.