Function deno_core::bin_op_sync [−][src]
pub fn bin_op_sync<F, R>(op_fn: F) -> Box<OpFn> where
F: Fn(&mut OpState, u32, &mut [ZeroCopyBuf]) -> Result<R, AnyError> + 'static,
R: ValueOrVector,
Creates an op that passes data synchronously using raw ui8 buffer.
The provided function op_fn
has the following parameters:
&mut OpState
: the op state, can be used to read/write resources in the runtime from an op.argument
: the i32 value that is passed to the Rust function.&mut [ZeroCopyBuf]
: raw bytes passed along.
op_fn
returns an array buffer value, which is directly returned to JavaScript.
When registering an op like this…
ⓘ
let mut runtime = JsRuntime::new(...); runtime.register_op("hello", deno_core::bin_op_sync(Self::hello_op));
…it can be invoked from JS using the provided name, for example:
Deno.core.ops();
let result = Deno.core.binOpSync("function_name", args);
The Deno.core.ops()
statement is needed once before any op calls, for initialization.
A more complete example is available in the examples directory.