mirror of
https://github.com/Start9Labs/rpc-toolkit.git
synced 2026-03-26 02:11:56 +00:00
support inheritance mapping
This commit is contained in:
@@ -67,7 +67,7 @@ impl<Context: crate::Context + Clone, Config: CommandFactory + FromArgMatches>
|
||||
parent_method: VecDeque::new(),
|
||||
method: method.clone(),
|
||||
params: params.clone(),
|
||||
inherited: Value::Object(InOMap::new()),
|
||||
inherited: crate::Empty {},
|
||||
})?;
|
||||
root_handler.cli_display(
|
||||
HandleAnyArgs {
|
||||
@@ -75,7 +75,7 @@ impl<Context: crate::Context + Clone, Config: CommandFactory + FromArgMatches>
|
||||
parent_method: VecDeque::new(),
|
||||
method,
|
||||
params,
|
||||
inherited: Value::Object(InOMap::new()),
|
||||
inherited: crate::Empty {},
|
||||
},
|
||||
res,
|
||||
)?;
|
||||
|
||||
@@ -10,11 +10,11 @@ use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
use yajrc::RpcError;
|
||||
|
||||
use crate::util::{internal_error, parse_error, Flat, PhantomData};
|
||||
use crate::util::{internal_error, Flat, PhantomData};
|
||||
use crate::{
|
||||
iter_from_ctx_and_handler, AnyContext, AnyHandler, CallRemote, CliBindings, DynHandler,
|
||||
EitherContext, Handler, HandlerArgs, HandlerArgsFor, HandlerTypes, IntoContext, IntoHandlers,
|
||||
PrintCliResult,
|
||||
OrEmpty, PrintCliResult,
|
||||
};
|
||||
|
||||
pub trait HandlerExt: Handler + Sized {
|
||||
@@ -106,18 +106,22 @@ impl<H: HandlerTypes> HandlerTypes for NoCli<H> {
|
||||
type Ok = H::Ok;
|
||||
type Err = H::Err;
|
||||
}
|
||||
impl<H> IntoHandlers for NoCli<H>
|
||||
impl<H, A, B> IntoHandlers<Flat<A, B>> for NoCli<H>
|
||||
where
|
||||
H: Handler,
|
||||
H::Params: DeserializeOwned,
|
||||
H::InheritedParams: DeserializeOwned,
|
||||
H::InheritedParams: OrEmpty<Flat<A, B>>,
|
||||
H::Ok: Serialize + DeserializeOwned,
|
||||
RpcError: From<H::Err>,
|
||||
A: Send + Sync + 'static,
|
||||
B: Send + Sync + 'static,
|
||||
{
|
||||
fn into_handlers(self) -> impl IntoIterator<Item = (Option<TypeId>, DynHandler)> {
|
||||
fn into_handlers(self) -> impl IntoIterator<Item = (Option<TypeId>, DynHandler<Flat<A, B>>)> {
|
||||
iter_from_ctx_and_handler(
|
||||
self.0.contexts(),
|
||||
DynHandler::WithoutCli(Arc::new(AnyHandler::new(self.0))),
|
||||
DynHandler::WithoutCli(Arc::new(AnyHandler::new(
|
||||
self.0.with_inherited(|a, b| OrEmpty::from_t(Flat(a, b))),
|
||||
))),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,7 +461,7 @@ where
|
||||
Context: IntoContext,
|
||||
F: Fn(Context, Params, InheritedParams) -> Result<T, E> + Send + Sync + Clone + 'static,
|
||||
Params: DeserializeOwned + Send + Sync + 'static,
|
||||
InheritedParams: DeserializeOwned + Send + Sync + 'static,
|
||||
InheritedParams: Send + Sync + 'static,
|
||||
T: Send + Sync + 'static,
|
||||
E: Send + Sync + 'static,
|
||||
{
|
||||
@@ -477,7 +477,7 @@ where
|
||||
Context: IntoContext,
|
||||
F: Fn(Context, Params, InheritedParams) -> Result<T, E> + Send + Sync + Clone + 'static,
|
||||
Params: DeserializeOwned + Send + Sync + 'static,
|
||||
InheritedParams: DeserializeOwned + Send + Sync + 'static,
|
||||
InheritedParams: Send + Sync + 'static,
|
||||
T: Send + Sync + 'static,
|
||||
E: Send + Sync + 'static,
|
||||
{
|
||||
@@ -515,7 +515,7 @@ where
|
||||
F: Fn(Context, Params, InheritedParams) -> Fut + Send + Sync + Clone + 'static,
|
||||
Fut: Future<Output = Result<T, E>> + Send + 'static,
|
||||
Params: DeserializeOwned + Send + Sync + 'static,
|
||||
InheritedParams: DeserializeOwned + Send + Sync + 'static,
|
||||
InheritedParams: Send + Sync + 'static,
|
||||
T: Send + Sync + 'static,
|
||||
E: Send + Sync + 'static,
|
||||
{
|
||||
@@ -532,7 +532,7 @@ where
|
||||
F: Fn(Context, Params, InheritedParams) -> Fut + Send + Sync + Clone + 'static,
|
||||
Fut: Future<Output = Result<T, E>> + Send + 'static,
|
||||
Params: DeserializeOwned + Send + Sync + 'static,
|
||||
InheritedParams: DeserializeOwned + Send + Sync + 'static,
|
||||
InheritedParams: Send + Sync + 'static,
|
||||
T: Send + Sync + 'static,
|
||||
E: Send + Sync + 'static,
|
||||
{
|
||||
|
||||
@@ -21,21 +21,20 @@ pub use adapters::*;
|
||||
pub use from_fn::*;
|
||||
pub use parent::*;
|
||||
|
||||
pub(crate) struct HandleAnyArgs {
|
||||
pub(crate) struct HandleAnyArgs<Inherited> {
|
||||
pub(crate) context: AnyContext,
|
||||
pub(crate) parent_method: VecDeque<&'static str>,
|
||||
pub(crate) method: VecDeque<&'static str>,
|
||||
pub(crate) params: Value,
|
||||
pub(crate) inherited: Value,
|
||||
pub(crate) inherited: Inherited,
|
||||
}
|
||||
impl HandleAnyArgs {
|
||||
impl<Inherited: Send + Sync> HandleAnyArgs<Inherited> {
|
||||
fn downcast<Context: IntoContext, H>(
|
||||
self,
|
||||
) -> Result<HandlerArgsFor<Context, H>, imbl_value::Error>
|
||||
where
|
||||
H: HandlerTypes,
|
||||
H: HandlerTypes<InheritedParams = Inherited>,
|
||||
H::Params: DeserializeOwned,
|
||||
H::InheritedParams: DeserializeOwned,
|
||||
{
|
||||
let Self {
|
||||
context,
|
||||
@@ -52,7 +51,7 @@ impl HandleAnyArgs {
|
||||
parent_method,
|
||||
method,
|
||||
params: imbl_value::from_value(params.clone())?,
|
||||
inherited_params: imbl_value::from_value(inherited.clone())?,
|
||||
inherited_params: inherited,
|
||||
raw_params: params,
|
||||
})
|
||||
}
|
||||
@@ -60,8 +59,12 @@ impl HandleAnyArgs {
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub(crate) trait HandleAny: Send + Sync {
|
||||
fn handle_sync(&self, handle_args: HandleAnyArgs) -> Result<Value, RpcError>;
|
||||
async fn handle_async(&self, handle_args: HandleAnyArgs) -> Result<Value, RpcError>;
|
||||
type Inherited: Send;
|
||||
fn handle_sync(&self, handle_args: HandleAnyArgs<Self::Inherited>) -> Result<Value, RpcError>;
|
||||
async fn handle_async(
|
||||
&self,
|
||||
handle_args: HandleAnyArgs<Self::Inherited>,
|
||||
) -> Result<Value, RpcError>;
|
||||
fn metadata(
|
||||
&self,
|
||||
method: VecDeque<&'static str>,
|
||||
@@ -71,10 +74,14 @@ pub(crate) trait HandleAny: Send + Sync {
|
||||
}
|
||||
#[async_trait::async_trait]
|
||||
impl<T: HandleAny> HandleAny for Arc<T> {
|
||||
fn handle_sync(&self, handle_args: HandleAnyArgs) -> Result<Value, RpcError> {
|
||||
type Inherited = T::Inherited;
|
||||
fn handle_sync(&self, handle_args: HandleAnyArgs<Self::Inherited>) -> Result<Value, RpcError> {
|
||||
self.deref().handle_sync(handle_args)
|
||||
}
|
||||
async fn handle_async(&self, handle_args: HandleAnyArgs) -> Result<Value, RpcError> {
|
||||
async fn handle_async(
|
||||
&self,
|
||||
handle_args: HandleAnyArgs<Self::Inherited>,
|
||||
) -> Result<Value, RpcError> {
|
||||
self.deref().handle_async(handle_args).await
|
||||
}
|
||||
fn metadata(
|
||||
@@ -90,13 +97,18 @@ impl<T: HandleAny> HandleAny for Arc<T> {
|
||||
}
|
||||
|
||||
pub(crate) trait CliBindingsAny {
|
||||
type Inherited;
|
||||
fn cli_command(&self, ctx_ty: TypeId) -> Command;
|
||||
fn cli_parse(
|
||||
&self,
|
||||
matches: &ArgMatches,
|
||||
ctx_ty: TypeId,
|
||||
) -> Result<(VecDeque<&'static str>, Value), clap::Error>;
|
||||
fn cli_display(&self, handle_args: HandleAnyArgs, result: Value) -> Result<(), RpcError>;
|
||||
fn cli_display(
|
||||
&self,
|
||||
handle_args: HandleAnyArgs<Self::Inherited>,
|
||||
result: Value,
|
||||
) -> Result<(), RpcError>;
|
||||
}
|
||||
|
||||
pub trait CliBindings: HandlerTypes {
|
||||
@@ -172,24 +184,41 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) trait HandleAnyWithCli: HandleAny + CliBindingsAny {}
|
||||
impl<T: HandleAny + CliBindingsAny> HandleAnyWithCli for T {}
|
||||
pub(crate) trait HandleAnyWithCli<Inherited>:
|
||||
HandleAny<Inherited = Inherited> + CliBindingsAny<Inherited = Inherited>
|
||||
{
|
||||
}
|
||||
impl<Inherited, T: HandleAny<Inherited = Inherited> + CliBindingsAny<Inherited = Inherited>>
|
||||
HandleAnyWithCli<Inherited> for T
|
||||
{
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[allow(private_interfaces)]
|
||||
pub enum DynHandler {
|
||||
WithoutCli(Arc<dyn HandleAny>),
|
||||
WithCli(Arc<dyn HandleAnyWithCli>),
|
||||
pub enum DynHandler<Inherited> {
|
||||
WithoutCli(Arc<dyn HandleAny<Inherited = Inherited>>),
|
||||
WithCli(Arc<dyn HandleAnyWithCli<Inherited>>),
|
||||
}
|
||||
impl<Inherited> Clone for DynHandler<Inherited> {
|
||||
fn clone(&self) -> Self {
|
||||
match self {
|
||||
Self::WithCli(a) => Self::WithCli(a.clone()),
|
||||
Self::WithoutCli(a) => Self::WithoutCli(a.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[async_trait::async_trait]
|
||||
impl HandleAny for DynHandler {
|
||||
fn handle_sync(&self, handle_args: HandleAnyArgs) -> Result<Value, RpcError> {
|
||||
impl<Inherited: Send> HandleAny for DynHandler<Inherited> {
|
||||
type Inherited = Inherited;
|
||||
fn handle_sync(&self, handle_args: HandleAnyArgs<Self::Inherited>) -> Result<Value, RpcError> {
|
||||
match self {
|
||||
DynHandler::WithoutCli(h) => h.handle_sync(handle_args),
|
||||
DynHandler::WithCli(h) => h.handle_sync(handle_args),
|
||||
}
|
||||
}
|
||||
async fn handle_async(&self, handle_args: HandleAnyArgs) -> Result<Value, RpcError> {
|
||||
async fn handle_async(
|
||||
&self,
|
||||
handle_args: HandleAnyArgs<Self::Inherited>,
|
||||
) -> Result<Value, RpcError> {
|
||||
match self {
|
||||
DynHandler::WithoutCli(h) => h.handle_async(handle_args).await,
|
||||
DynHandler::WithCli(h) => h.handle_async(handle_args).await,
|
||||
@@ -309,11 +338,11 @@ impl<H: std::fmt::Debug> std::fmt::Debug for AnyHandler<H> {
|
||||
impl<H: Handler> HandleAny for AnyHandler<H>
|
||||
where
|
||||
H::Params: DeserializeOwned,
|
||||
H::InheritedParams: DeserializeOwned,
|
||||
H::Ok: Serialize,
|
||||
RpcError: From<H::Err>,
|
||||
{
|
||||
fn handle_sync(&self, handle_args: HandleAnyArgs) -> Result<Value, RpcError> {
|
||||
type Inherited = H::InheritedParams;
|
||||
fn handle_sync(&self, handle_args: HandleAnyArgs<Self::Inherited>) -> Result<Value, RpcError> {
|
||||
imbl_value::to_value(
|
||||
&self
|
||||
.0
|
||||
@@ -321,7 +350,10 @@ where
|
||||
)
|
||||
.map_err(internal_error)
|
||||
}
|
||||
async fn handle_async(&self, handle_args: HandleAnyArgs) -> Result<Value, RpcError> {
|
||||
async fn handle_async(
|
||||
&self,
|
||||
handle_args: HandleAnyArgs<Self::Inherited>,
|
||||
) -> Result<Value, RpcError> {
|
||||
imbl_value::to_value(
|
||||
&self
|
||||
.0
|
||||
@@ -346,10 +378,10 @@ impl<H: CliBindings> CliBindingsAny for AnyHandler<H>
|
||||
where
|
||||
H: CliBindings,
|
||||
H::Params: DeserializeOwned,
|
||||
H::InheritedParams: DeserializeOwned,
|
||||
H::Ok: Serialize + DeserializeOwned,
|
||||
RpcError: From<H::Err>,
|
||||
{
|
||||
type Inherited = H::InheritedParams;
|
||||
fn cli_command(&self, ctx_ty: TypeId) -> Command {
|
||||
self.0.cli_command(ctx_ty)
|
||||
}
|
||||
@@ -360,7 +392,11 @@ where
|
||||
) -> Result<(VecDeque<&'static str>, Value), clap::Error> {
|
||||
self.0.cli_parse(matches, ctx_ty)
|
||||
}
|
||||
fn cli_display(&self, handle_args: HandleAnyArgs, result: Value) -> Result<(), RpcError> {
|
||||
fn cli_display(
|
||||
&self,
|
||||
handle_args: HandleAnyArgs<Self::Inherited>,
|
||||
result: Value,
|
||||
) -> Result<(), RpcError> {
|
||||
self.0
|
||||
.cli_display(
|
||||
handle_args.downcast::<_, H>().map_err(invalid_params)?,
|
||||
@@ -373,9 +409,19 @@ where
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize, Parser)]
|
||||
pub struct Empty {}
|
||||
|
||||
pub(crate) trait OrEmpty<T> {}
|
||||
impl<T> OrEmpty<T> for T {}
|
||||
impl<A, B> OrEmpty<Flat<A, B>> for Empty {}
|
||||
pub(crate) trait OrEmpty<T> {
|
||||
fn from_t(t: T) -> Self;
|
||||
}
|
||||
impl<T> OrEmpty<T> for T {
|
||||
fn from_t(t: T) -> Self {
|
||||
t
|
||||
}
|
||||
}
|
||||
impl<A, B> OrEmpty<Flat<A, B>> for Empty {
|
||||
fn from_t(t: Flat<A, B>) -> Self {
|
||||
Empty {}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize, Parser)]
|
||||
pub enum Never {}
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||
|
||||
use clap::{ArgMatches, Command, CommandFactory, FromArgMatches};
|
||||
use imbl_value::imbl::{OrdMap, OrdSet};
|
||||
use imbl_value::{to_value, Value};
|
||||
use imbl_value::Value;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
use yajrc::RpcError;
|
||||
@@ -12,33 +12,37 @@ use yajrc::RpcError;
|
||||
use crate::util::{combine, Flat, PhantomData};
|
||||
use crate::{
|
||||
AnyContext, AnyHandler, CliBindings, DynHandler, Empty, HandleAny, HandleAnyArgs, Handler,
|
||||
HandlerArgs, HandlerArgsFor, HandlerTypes, IntoContext, OrEmpty,
|
||||
HandlerArgs, HandlerArgsFor, HandlerExt, HandlerTypes, IntoContext, OrEmpty,
|
||||
};
|
||||
|
||||
pub trait IntoHandlers: HandlerTypes {
|
||||
fn into_handlers(self) -> impl IntoIterator<Item = (Option<TypeId>, DynHandler)>;
|
||||
pub trait IntoHandlers<Inherited>: HandlerTypes {
|
||||
fn into_handlers(self) -> impl IntoIterator<Item = (Option<TypeId>, DynHandler<Inherited>)>;
|
||||
}
|
||||
|
||||
impl<H> IntoHandlers for H
|
||||
impl<H, A, B> IntoHandlers<Flat<A, B>> for H
|
||||
where
|
||||
H: Handler + CliBindings,
|
||||
H::Params: DeserializeOwned,
|
||||
H::InheritedParams: DeserializeOwned,
|
||||
H::InheritedParams: OrEmpty<Flat<A, B>>,
|
||||
H::Ok: Serialize + DeserializeOwned,
|
||||
RpcError: From<H::Err>,
|
||||
A: Send + Sync + 'static,
|
||||
B: Send + Sync + 'static,
|
||||
{
|
||||
fn into_handlers(self) -> impl IntoIterator<Item = (Option<TypeId>, DynHandler)> {
|
||||
fn into_handlers(self) -> impl IntoIterator<Item = (Option<TypeId>, DynHandler<Flat<A, B>>)> {
|
||||
iter_from_ctx_and_handler(
|
||||
intersect_type_ids(self.contexts(), <Self as CliBindings>::Context::type_ids()),
|
||||
DynHandler::WithCli(Arc::new(AnyHandler::new(self))),
|
||||
DynHandler::WithCli(Arc::new(AnyHandler::new(
|
||||
self.with_inherited(|a, b| OrEmpty::from_t(Flat(a, b))),
|
||||
))),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn iter_from_ctx_and_handler(
|
||||
pub(crate) fn iter_from_ctx_and_handler<Inherited>(
|
||||
ctx: Option<OrdSet<TypeId>>,
|
||||
handler: DynHandler,
|
||||
) -> impl IntoIterator<Item = (Option<TypeId>, DynHandler)> {
|
||||
handler: DynHandler<Inherited>,
|
||||
) -> impl IntoIterator<Item = (Option<TypeId>, DynHandler<Inherited>)> {
|
||||
if let Some(ctx) = ctx {
|
||||
itertools::Either::Left(ctx.into_iter().map(Some))
|
||||
} else {
|
||||
@@ -67,13 +71,19 @@ impl<'a> std::borrow::Borrow<Option<&'a str>> for Name {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct SubcommandMap(pub(crate) OrdMap<Name, OrdMap<Option<TypeId>, DynHandler>>);
|
||||
impl SubcommandMap {
|
||||
pub(crate) struct SubcommandMap<Inherited>(
|
||||
pub(crate) OrdMap<Name, OrdMap<Option<TypeId>, DynHandler<Inherited>>>,
|
||||
);
|
||||
impl<Inherited> Clone for SubcommandMap<Inherited> {
|
||||
fn clone(&self) -> Self {
|
||||
Self(self.0.clone())
|
||||
}
|
||||
}
|
||||
impl<Inherited> SubcommandMap<Inherited> {
|
||||
fn insert(
|
||||
&mut self,
|
||||
name: Option<&'static str>,
|
||||
handlers: impl IntoIterator<Item = (Option<TypeId>, DynHandler)>,
|
||||
handlers: impl IntoIterator<Item = (Option<TypeId>, DynHandler<Inherited>)>,
|
||||
) {
|
||||
let mut for_name = self.0.remove(&name).unwrap_or_default();
|
||||
for (ctx_ty, handler) in handlers {
|
||||
@@ -82,7 +92,11 @@ impl SubcommandMap {
|
||||
self.0.insert(Name(name), for_name);
|
||||
}
|
||||
|
||||
fn get<'a>(&'a self, ctx_ty: TypeId, name: Option<&str>) -> Option<(Name, &'a DynHandler)> {
|
||||
fn get<'a>(
|
||||
&'a self,
|
||||
ctx_ty: TypeId,
|
||||
name: Option<&str>,
|
||||
) -> Option<(Name, &'a DynHandler<Inherited>)> {
|
||||
if let Some((name, for_name)) = self.0.get_key_value(&name) {
|
||||
if let Some(for_ctx) = for_name.get(&Some(ctx_ty)) {
|
||||
Some((*name, for_ctx))
|
||||
@@ -96,8 +110,8 @@ impl SubcommandMap {
|
||||
}
|
||||
|
||||
pub struct ParentHandler<Params = Empty, InheritedParams = Empty> {
|
||||
_phantom: PhantomData<(Params, InheritedParams)>,
|
||||
pub(crate) subcommands: SubcommandMap,
|
||||
_phantom: PhantomData<Params>,
|
||||
pub(crate) subcommands: SubcommandMap<Flat<Params, InheritedParams>>,
|
||||
metadata: OrdMap<&'static str, Value>,
|
||||
}
|
||||
impl<Params, InheritedParams> ParentHandler<Params, InheritedParams> {
|
||||
@@ -141,8 +155,7 @@ impl<Params, InheritedParams> ParentHandler<Params, InheritedParams> {
|
||||
#[allow(private_bounds)]
|
||||
pub fn subcommand<H>(mut self, name: &'static str, handler: H) -> Self
|
||||
where
|
||||
H: IntoHandlers,
|
||||
H::InheritedParams: OrEmpty<Flat<Params, InheritedParams>>,
|
||||
H: IntoHandlers<Flat<Params, InheritedParams>>,
|
||||
{
|
||||
self.subcommands
|
||||
.insert(name.into(), handler.into_handlers());
|
||||
@@ -151,8 +164,7 @@ impl<Params, InheritedParams> ParentHandler<Params, InheritedParams> {
|
||||
#[allow(private_bounds)]
|
||||
pub fn root_handler<H>(mut self, handler: H) -> Self
|
||||
where
|
||||
H: IntoHandlers<Params = Empty>,
|
||||
H::InheritedParams: OrEmpty<Flat<Params, InheritedParams>>,
|
||||
H: IntoHandlers<Flat<Params, InheritedParams>>,
|
||||
{
|
||||
self.subcommands.insert(None, handler.into_handlers());
|
||||
self
|
||||
@@ -182,9 +194,9 @@ where
|
||||
context,
|
||||
mut parent_method,
|
||||
mut method,
|
||||
params,
|
||||
inherited_params,
|
||||
raw_params,
|
||||
..
|
||||
}: HandlerArgsFor<AnyContext, Self>,
|
||||
) -> Result<Self::Ok, Self::Err> {
|
||||
let cmd = method.pop_front();
|
||||
@@ -197,7 +209,7 @@ where
|
||||
parent_method,
|
||||
method,
|
||||
params: raw_params,
|
||||
inherited: to_value(&inherited_params)?,
|
||||
inherited: Flat(params, inherited_params),
|
||||
})
|
||||
} else {
|
||||
Err(yajrc::METHOD_NOT_FOUND_ERROR)
|
||||
@@ -209,9 +221,9 @@ where
|
||||
context,
|
||||
mut parent_method,
|
||||
mut method,
|
||||
params,
|
||||
inherited_params,
|
||||
raw_params,
|
||||
..
|
||||
}: HandlerArgsFor<AnyContext, Self>,
|
||||
) -> Result<Self::Ok, Self::Err> {
|
||||
let cmd = method.pop_front();
|
||||
@@ -225,7 +237,7 @@ where
|
||||
parent_method,
|
||||
method,
|
||||
params: raw_params,
|
||||
inherited: to_value(&inherited_params)?,
|
||||
inherited: Flat(params, inherited_params),
|
||||
})
|
||||
.await
|
||||
} else {
|
||||
@@ -330,9 +342,9 @@ where
|
||||
context,
|
||||
mut parent_method,
|
||||
mut method,
|
||||
params,
|
||||
inherited_params,
|
||||
raw_params,
|
||||
..
|
||||
}: HandlerArgsFor<AnyContext, Self>,
|
||||
result: Self::Ok,
|
||||
) -> Result<(), Self::Err> {
|
||||
@@ -349,7 +361,7 @@ where
|
||||
parent_method,
|
||||
method,
|
||||
params: raw_params,
|
||||
inherited: to_value(&inherited_params)?,
|
||||
inherited: Flat(params, inherited_params),
|
||||
},
|
||||
result,
|
||||
)
|
||||
|
||||
@@ -8,7 +8,7 @@ use imbl_value::{InOMap, Value};
|
||||
use yajrc::{RpcError, RpcMethod};
|
||||
|
||||
use crate::util::{invalid_request, JobRunner};
|
||||
use crate::{AnyHandler, HandleAny, HandleAnyArgs, IntoContext, ParentHandler};
|
||||
use crate::{AnyHandler, Empty, HandleAny, HandleAnyArgs, IntoContext, ParentHandler};
|
||||
|
||||
pub type GenericRpcMethod = yajrc::GenericRpcMethod<String, Value, Value>;
|
||||
pub type RpcRequest = yajrc::RpcRequest<GenericRpcMethod>;
|
||||
@@ -66,7 +66,7 @@ impl<Context: crate::Context> Server<Context> {
|
||||
parent_method: VecDeque::new(),
|
||||
method: method.ok_or_else(|| yajrc::METHOD_NOT_FOUND_ERROR)?,
|
||||
params,
|
||||
inherited: Value::Object(InOMap::new()),
|
||||
inherited: crate::Empty {},
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ fn make_api() -> ParentHandler {
|
||||
.subcommand(
|
||||
"fizz",
|
||||
ParentHandler::<InheritParams>::new().root_handler(
|
||||
from_fn(|c: CliContext, _, InheritParams { donde }| {
|
||||
from_fn(|c: CliContext, _: Empty, InheritParams { donde }| {
|
||||
Ok::<_, RpcError>(
|
||||
format!(
|
||||
"Root Command: Host {host} Donde = {donde}",
|
||||
@@ -174,7 +174,7 @@ fn make_api() -> ParentHandler {
|
||||
.subcommand(
|
||||
"error",
|
||||
ParentHandler::<InheritParams>::new().root_handler(
|
||||
from_fn(|c: CliContext, _, InheritParams { donde }| {
|
||||
from_fn(|c: CliContext, _: Empty, InheritParams { donde }| {
|
||||
Err::<String, _>(RpcError {
|
||||
code: 1,
|
||||
message: "This is an example message".into(),
|
||||
|
||||
Reference in New Issue
Block a user