macro_rules! extension { ( $name:ident $(, deps = [ $( $dep:ident ),* ] )? $(, parameters = [ $( $param:ident : $type:ident ),+ ] )? $(, ops_fn = $ops_symbol:ident $( < $ops_param:ident > )? )? $(, ops = [ $( $(#[$m:meta])* $( $op:ident )::+ $( < $op_param:ident > )? ),+ $(,)? ] )? $(, esm_entry_point = $esm_entry_point:literal )? $(, esm = [ $( dir $dir_esm:literal , )? $( $esm:literal ),* $(,)? ] )? $(, esm_setup_script = $esm_setup_script:expr )? $(, js = [ $( dir $dir_js:literal , )? $( $js:literal ),* $(,)? ] )? $(, options = { $( $options_id:ident : $options_type:ty ),* $(,)? } )? $(, middleware = $middleware_fn:expr )? $(, state = $state_fn:expr )? $(, event_loop_middleware = $event_loop_middleware_fn:ident )? $(, customizer = $customizer_fn:expr )? $(,)? ) => { ... }; (! __config__ $ext:ident $( parameters = [ $( $param:ident : $type:ident ),+ ] )? config = { $( $options_id:ident : $options_type:ty ),* } $( state_fn = $state_fn:expr )? ) => { ... }; (! __config__ $ext:ident $( parameters = [ $( $param:ident : $type:ident ),+ ] )? $( state_fn = $state_fn:expr )? ) => { ... }; (! __ops__ $ext:ident __eot__) => { ... }; (! __ops__ $ext:ident $ops_symbol:ident __eot__) => { ... }; (! __ops__ $ext:ident $ops_symbol:ident < $ops_param:ident > __eot__) => { ... }; }
Expand description
Defines a Deno extension. The first parameter is the name of the extension symbol namespace to create. This is the symbol you will use to refer to the extension.
Most extensions will define a combination of ops and ESM files, like so:
#[op]
fn op_xyz() {
}
deno_core::extension!(
my_extension,
ops = [ op_xyz ],
esm = [ "my_script.js" ],
);
The following options are available for the extension
macro:
- deps: a comma-separated list of module dependencies, eg:
deps = [ my_other_extension ]
- parameters: a comma-separated list of parameters and base traits, eg:
parameters = [ P: MyTrait ]
- ops: a comma-separated list of
OpDecl
s to provide, eg:ops = [ op_foo, op_bar ]
- esm: a comma-separated list of ESM module filenames (see
include_js_files
), eg:esm = [ dir "dir", "my_file.js" ]
- esm_setup_script: see [
ExtensionBuilder::esm_setup_script
] - js: a comma-separated list of JS filenames (see
include_js_files
), eg:js = [ dir "dir", "my_file.js" ]
- config: a structure-like definition for configuration parameters which will be required when initializing this extension, eg:
config = { my_param: Option<usize> }
- middleware: an
OpDecl
middleware function with the signaturefn (OpDecl) -> OpDecl
- state: a state initialization function, with the signature
fn (&mut OpState, ...) -> ()
, where...
are parameters matching the fields of the config struct - event_loop_middleware: an event-loop middleware function (see
ExtensionBuilder::event_loop_middleware
)