From 875d4beacb5bd631f97c8ce424d4a4ab19423a99 Mon Sep 17 00:00:00 2001 From: J H Date: Mon, 18 Dec 2023 10:27:49 -0700 Subject: [PATCH] feat: Add more helper --- rpc-toolkit/src/handler.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/rpc-toolkit/src/handler.rs b/rpc-toolkit/src/handler.rs index 3a2fb53..82f4eab 100644 --- a/rpc-toolkit/src/handler.rs +++ b/rpc-toolkit/src/handler.rs @@ -396,7 +396,11 @@ where } impl ParentHandler { - pub fn subcommand(mut self, name: Option<&'static str>, handler: H) -> Self + pub fn subcommand( + mut self, + name: impl Into>, + handler: H, + ) -> Self where Context: IntoContext, H: Handler + PrintCliResult + 'static, @@ -406,7 +410,7 @@ impl ParentHandler { { self.subcommands.insert( handler.contexts(), - name, + name.into(), DynHandler::WithCli(Arc::new(AnyHandler { _ctx: PhantomData, handler: WithCliBindings { @@ -417,7 +421,11 @@ impl ParentHandler { ); self } - pub fn subcommand_no_cli(mut self, name: Option<&'static str>, handler: H) -> Self + pub fn subcommand_no_cli( + mut self, + name: impl Into>, + handler: H, + ) -> Self where Context: IntoContext, H: Handler + 'static, @@ -427,7 +435,7 @@ impl ParentHandler { { self.subcommands.insert( handler.contexts(), - name, + name.into(), DynHandler::WithoutCli(Arc::new(AnyHandler { _ctx: PhantomData, handler, @@ -443,7 +451,7 @@ where { pub fn subcommand_with_inherited( mut self, - name: Option<&'static str>, + name: impl Into>, handler: H, inherit: F, ) -> Self @@ -457,7 +465,7 @@ where { self.subcommands.insert( handler.contexts(), - name, + name.into(), DynHandler::WithCli(Arc::new(AnyHandler { _ctx: PhantomData, handler: WithCliBindings { @@ -474,7 +482,7 @@ where } pub fn subcommand_with_inherited_no_cli( mut self, - name: Option<&'static str>, + name: impl Into>, handler: H, inherit: F, ) -> Self @@ -488,7 +496,7 @@ where { self.subcommands.insert( handler.contexts(), - name, + name.into(), DynHandler::WithoutCli(Arc::new(AnyHandler { _ctx: PhantomData, handler: InheritanceHandler:: {