From fbb69329343c9985c26181e6297e6556c46d381d Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Thu, 29 Jun 2023 10:23:14 -0600 Subject: refactor(ops): op2 support for generics (#19636) Implementation of generics for `#[op2]`, along with some refactoring to improve the ergonomics of ops with generics parameters: - The ops have generics on the struct rather than the associated methods, which allows us to trait-ify ops (impossible when they are on the methods) - The decl() method can become a trait-associated const field which unlocks future optimizations Callers of ops need to switch from: `op_net_connect_tcp::call::(conn_state, ip_addr)` to `op_net_connect_tcp::::call(conn_state, ip_addr)`. --- core/extensions.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'core/extensions.rs') diff --git a/core/extensions.rs b/core/extensions.rs index fa6d7851e..e76b4064b 100644 --- a/core/extensions.rs +++ b/core/extensions.rs @@ -65,6 +65,12 @@ pub type OpMiddlewareFn = dyn Fn(OpDecl) -> OpDecl; pub type OpStateFn = dyn FnOnce(&mut OpState); pub type OpEventLoopFn = dyn Fn(Rc>, &mut Context) -> bool; +/// Trait implemented by all generated ops. +pub trait Op { + const NAME: &'static str; + const DECL: OpDecl; +} + pub struct OpDecl { pub name: &'static str, pub v8_fn_ptr: OpFnRef, @@ -239,7 +245,7 @@ macro_rules! extension { ext.ops(vec![ $( $( #[ $m ] )* - $( $op )::+ :: decl $( :: < $($op_param),* > )? () + $( $op )::+ $( :: < $($op_param),* > )? :: decl () ),+ ]); )? -- cgit v1.2.3