mirror of
https://github.com/Start9Labs/rpc-toolkit.git
synced 2026-03-30 12:21:58 +00:00
root handler
This commit is contained in:
@@ -396,11 +396,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<Params, InheritedParams> ParentHandler<Params, InheritedParams> {
|
impl<Params, InheritedParams> ParentHandler<Params, InheritedParams> {
|
||||||
pub fn subcommand<Context, H>(
|
pub fn subcommand<Context, H>(mut self, name: &'static str, handler: H) -> Self
|
||||||
mut self,
|
|
||||||
name: impl Into<Option<&'static str>>,
|
|
||||||
handler: H,
|
|
||||||
) -> Self
|
|
||||||
where
|
where
|
||||||
Context: IntoContext,
|
Context: IntoContext,
|
||||||
H: Handler<Context, InheritedParams = NoParams> + PrintCliResult<Context> + 'static,
|
H: Handler<Context, InheritedParams = NoParams> + PrintCliResult<Context> + 'static,
|
||||||
@@ -421,11 +417,7 @@ impl<Params, InheritedParams> ParentHandler<Params, InheritedParams> {
|
|||||||
);
|
);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
pub fn subcommand_no_cli<Context, H>(
|
pub fn subcommand_no_cli<Context, H>(mut self, name: &'static str, handler: H) -> Self
|
||||||
mut self,
|
|
||||||
name: impl Into<Option<&'static str>>,
|
|
||||||
handler: H,
|
|
||||||
) -> Self
|
|
||||||
where
|
where
|
||||||
Context: IntoContext,
|
Context: IntoContext,
|
||||||
H: Handler<Context, InheritedParams = NoParams> + 'static,
|
H: Handler<Context, InheritedParams = NoParams> + 'static,
|
||||||
@@ -451,7 +443,7 @@ where
|
|||||||
{
|
{
|
||||||
pub fn subcommand_with_inherited<Context, H, F>(
|
pub fn subcommand_with_inherited<Context, H, F>(
|
||||||
mut self,
|
mut self,
|
||||||
name: impl Into<Option<&'static str>>,
|
name: &'static str,
|
||||||
handler: H,
|
handler: H,
|
||||||
inherit: F,
|
inherit: F,
|
||||||
) -> Self
|
) -> Self
|
||||||
@@ -482,7 +474,7 @@ where
|
|||||||
}
|
}
|
||||||
pub fn subcommand_with_inherited_no_cli<Context, H, F>(
|
pub fn subcommand_with_inherited_no_cli<Context, H, F>(
|
||||||
mut self,
|
mut self,
|
||||||
name: impl Into<Option<&'static str>>,
|
name: &'static str,
|
||||||
handler: H,
|
handler: H,
|
||||||
inherit: F,
|
inherit: F,
|
||||||
) -> Self
|
) -> Self
|
||||||
@@ -508,6 +500,55 @@ where
|
|||||||
);
|
);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
pub fn root_handler<Context, H, F>(mut self, handler: H, inherit: F) -> Self
|
||||||
|
where
|
||||||
|
Context: IntoContext,
|
||||||
|
H: Handler<Context, Params = NoParams> + PrintCliResult<Context> + 'static,
|
||||||
|
H::Params: FromArgMatches + CommandFactory + Serialize + DeserializeOwned,
|
||||||
|
H::Ok: Serialize + DeserializeOwned,
|
||||||
|
RpcError: From<H::Err>,
|
||||||
|
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::<Context, Params, InheritedParams, H, F> {
|
||||||
|
_phantom: PhantomData,
|
||||||
|
handler,
|
||||||
|
inherit,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
pub fn root_handler_no_cli<Context, H, F>(mut self, handler: H, inherit: F) -> Self
|
||||||
|
where
|
||||||
|
Context: IntoContext,
|
||||||
|
H: Handler<Context, Params = NoParams> + 'static,
|
||||||
|
H::Params: DeserializeOwned,
|
||||||
|
H::Ok: Serialize,
|
||||||
|
RpcError: From<H::Err>,
|
||||||
|
F: Fn(Params, InheritedParams) -> H::InheritedParams + 'static,
|
||||||
|
{
|
||||||
|
self.subcommands.insert(
|
||||||
|
handler.contexts(),
|
||||||
|
None,
|
||||||
|
DynHandler::WithoutCli(Arc::new(AnyHandler {
|
||||||
|
_ctx: PhantomData,
|
||||||
|
handler: InheritanceHandler::<Context, Params, InheritedParams, H, F> {
|
||||||
|
_phantom: PhantomData,
|
||||||
|
handler,
|
||||||
|
inherit,
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Params: Serialize, InheritedParams: Serialize> Handler<AnyContext>
|
impl<Params: Serialize, InheritedParams: Serialize> Handler<AnyContext>
|
||||||
|
|||||||
Reference in New Issue
Block a user