diff --git a/rpc-toolkit/src/handler.rs b/rpc-toolkit/src/handler.rs index 82f4eab..ab1c498 100644 --- a/rpc-toolkit/src/handler.rs +++ b/rpc-toolkit/src/handler.rs @@ -396,11 +396,7 @@ where } impl ParentHandler { - pub fn subcommand( - mut self, - name: impl Into>, - handler: H, - ) -> Self + pub fn subcommand(mut self, name: &'static str, handler: H) -> Self where Context: IntoContext, H: Handler + PrintCliResult + 'static, @@ -421,11 +417,7 @@ impl ParentHandler { ); self } - pub fn subcommand_no_cli( - mut self, - name: impl Into>, - handler: H, - ) -> Self + pub fn subcommand_no_cli(mut self, name: &'static str, handler: H) -> Self where Context: IntoContext, H: Handler + 'static, @@ -451,7 +443,7 @@ where { pub fn subcommand_with_inherited( mut self, - name: impl Into>, + name: &'static str, handler: H, inherit: F, ) -> Self @@ -482,7 +474,7 @@ where } pub fn subcommand_with_inherited_no_cli( mut self, - name: impl Into>, + name: &'static str, handler: H, inherit: F, ) -> Self @@ -508,6 +500,55 @@ where ); self } + pub fn root_handler(mut self, handler: H, inherit: F) -> Self + where + Context: IntoContext, + H: Handler + PrintCliResult + 'static, + H::Params: FromArgMatches + CommandFactory + Serialize + DeserializeOwned, + H::Ok: Serialize + DeserializeOwned, + RpcError: From, + F: Fn(Params, InheritedParams) -> H::InheritedParams + 'static, + { + self.subcommands.insert( + handler.contexts(), + None, + DynHandler::WithCli(Arc::new(AnyHandler { + _ctx: PhantomData, + handler: WithCliBindings { + _ctx: PhantomData, + handler: InheritanceHandler:: { + _phantom: PhantomData, + handler, + inherit, + }, + }, + })), + ); + self + } + pub fn root_handler_no_cli(mut self, handler: H, inherit: F) -> Self + where + Context: IntoContext, + H: Handler + 'static, + H::Params: DeserializeOwned, + H::Ok: Serialize, + RpcError: From, + F: Fn(Params, InheritedParams) -> H::InheritedParams + 'static, + { + self.subcommands.insert( + handler.contexts(), + None, + DynHandler::WithoutCli(Arc::new(AnyHandler { + _ctx: PhantomData, + handler: InheritanceHandler:: { + _phantom: PhantomData, + handler, + inherit, + }, + })), + ); + self + } } impl Handler