Macro deno_core::ops

source ·
macro_rules! ops {
    ($name:ident, parameters = [ $( $param:ident : $type:ident ),+ ], ops = [ $( $(#[$m:meta])* $( $op:ident )::+ $( < $op_param:ident > )?  ),+ $(,)? ]) => { ... };
    ($name:ident, [ $( $(#[$m:meta])* $( $op:ident )::+ ),+ $(,)? ] ) => { ... };
}
Expand description

Declares a block of Deno #[op]s. The first parameter determines the name of the op declaration block, and is usually deno_ops. This block generates a function that returns a Vec<OpDecl>.

This can be either a compact form like:

# use deno_core::*;
#[op]
fn op_xyz() {}

deno_core::ops!(deno_ops, [
  op_xyz
]);

// Use the ops:
deno_ops()

… or a parameterized form like so that allows passing a number of type parameters to each #[op]:

# use deno_core::*;
#[op]
fn op_xyz<P>() where P: Clone {}

deno_core::ops!(deno_ops,
  parameters = [P: Clone],
  ops = [
    op_xyz<P>
  ]
);

// Use the ops, with `String` as the parameter `P`:
deno_ops::<String>()