support inheritance mapping

This commit is contained in:
Aiden McClelland
2024-02-17 19:25:13 -07:00
parent 85144f1f70
commit c89e0abdb1
7 changed files with 134 additions and 72 deletions

View File

@@ -67,7 +67,7 @@ impl<Context: crate::Context + Clone, Config: CommandFactory + FromArgMatches>
parent_method: VecDeque::new(), parent_method: VecDeque::new(),
method: method.clone(), method: method.clone(),
params: params.clone(), params: params.clone(),
inherited: Value::Object(InOMap::new()), inherited: crate::Empty {},
})?; })?;
root_handler.cli_display( root_handler.cli_display(
HandleAnyArgs { HandleAnyArgs {
@@ -75,7 +75,7 @@ impl<Context: crate::Context + Clone, Config: CommandFactory + FromArgMatches>
parent_method: VecDeque::new(), parent_method: VecDeque::new(),
method, method,
params, params,
inherited: Value::Object(InOMap::new()), inherited: crate::Empty {},
}, },
res, res,
)?; )?;

View File

@@ -10,11 +10,11 @@ use serde::de::DeserializeOwned;
use serde::Serialize; use serde::Serialize;
use yajrc::RpcError; use yajrc::RpcError;
use crate::util::{internal_error, parse_error, Flat, PhantomData}; use crate::util::{internal_error, Flat, PhantomData};
use crate::{ use crate::{
iter_from_ctx_and_handler, AnyContext, AnyHandler, CallRemote, CliBindings, DynHandler, iter_from_ctx_and_handler, AnyContext, AnyHandler, CallRemote, CliBindings, DynHandler,
EitherContext, Handler, HandlerArgs, HandlerArgsFor, HandlerTypes, IntoContext, IntoHandlers, EitherContext, Handler, HandlerArgs, HandlerArgsFor, HandlerTypes, IntoContext, IntoHandlers,
PrintCliResult, OrEmpty, PrintCliResult,
}; };
pub trait HandlerExt: Handler + Sized { pub trait HandlerExt: Handler + Sized {
@@ -106,18 +106,22 @@ impl<H: HandlerTypes> HandlerTypes for NoCli<H> {
type Ok = H::Ok; type Ok = H::Ok;
type Err = H::Err; type Err = H::Err;
} }
impl<H> IntoHandlers for NoCli<H> impl<H, A, B> IntoHandlers<Flat<A, B>> for NoCli<H>
where where
H: Handler, H: Handler,
H::Params: DeserializeOwned, H::Params: DeserializeOwned,
H::InheritedParams: DeserializeOwned, H::InheritedParams: OrEmpty<Flat<A, B>>,
H::Ok: Serialize + DeserializeOwned, H::Ok: Serialize + DeserializeOwned,
RpcError: From<H::Err>, 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( iter_from_ctx_and_handler(
self.0.contexts(), 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))),
))),
) )
} }
} }

View File

@@ -461,7 +461,7 @@ where
Context: IntoContext, Context: IntoContext,
F: Fn(Context, Params, InheritedParams) -> Result<T, E> + Send + Sync + Clone + 'static, F: Fn(Context, Params, InheritedParams) -> Result<T, E> + Send + Sync + Clone + 'static,
Params: DeserializeOwned + Send + Sync + 'static, Params: DeserializeOwned + Send + Sync + 'static,
InheritedParams: DeserializeOwned + Send + Sync + 'static, InheritedParams: Send + Sync + 'static,
T: Send + Sync + 'static, T: Send + Sync + 'static,
E: Send + Sync + 'static, E: Send + Sync + 'static,
{ {
@@ -477,7 +477,7 @@ where
Context: IntoContext, Context: IntoContext,
F: Fn(Context, Params, InheritedParams) -> Result<T, E> + Send + Sync + Clone + 'static, F: Fn(Context, Params, InheritedParams) -> Result<T, E> + Send + Sync + Clone + 'static,
Params: DeserializeOwned + Send + Sync + 'static, Params: DeserializeOwned + Send + Sync + 'static,
InheritedParams: DeserializeOwned + Send + Sync + 'static, InheritedParams: Send + Sync + 'static,
T: Send + Sync + 'static, T: Send + Sync + 'static,
E: Send + Sync + 'static, E: Send + Sync + 'static,
{ {
@@ -515,7 +515,7 @@ where
F: Fn(Context, Params, InheritedParams) -> Fut + Send + Sync + Clone + 'static, F: Fn(Context, Params, InheritedParams) -> Fut + Send + Sync + Clone + 'static,
Fut: Future<Output = Result<T, E>> + Send + 'static, Fut: Future<Output = Result<T, E>> + Send + 'static,
Params: DeserializeOwned + Send + Sync + 'static, Params: DeserializeOwned + Send + Sync + 'static,
InheritedParams: DeserializeOwned + Send + Sync + 'static, InheritedParams: Send + Sync + 'static,
T: Send + Sync + 'static, T: Send + Sync + 'static,
E: Send + Sync + 'static, E: Send + Sync + 'static,
{ {
@@ -532,7 +532,7 @@ where
F: Fn(Context, Params, InheritedParams) -> Fut + Send + Sync + Clone + 'static, F: Fn(Context, Params, InheritedParams) -> Fut + Send + Sync + Clone + 'static,
Fut: Future<Output = Result<T, E>> + Send + 'static, Fut: Future<Output = Result<T, E>> + Send + 'static,
Params: DeserializeOwned + Send + Sync + 'static, Params: DeserializeOwned + Send + Sync + 'static,
InheritedParams: DeserializeOwned + Send + Sync + 'static, InheritedParams: Send + Sync + 'static,
T: Send + Sync + 'static, T: Send + Sync + 'static,
E: Send + Sync + 'static, E: Send + Sync + 'static,
{ {

View File

@@ -21,21 +21,20 @@ pub use adapters::*;
pub use from_fn::*; pub use from_fn::*;
pub use parent::*; pub use parent::*;
pub(crate) struct HandleAnyArgs { pub(crate) struct HandleAnyArgs<Inherited> {
pub(crate) context: AnyContext, pub(crate) context: AnyContext,
pub(crate) parent_method: VecDeque<&'static str>, pub(crate) parent_method: VecDeque<&'static str>,
pub(crate) method: VecDeque<&'static str>, pub(crate) method: VecDeque<&'static str>,
pub(crate) params: Value, 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>( fn downcast<Context: IntoContext, H>(
self, self,
) -> Result<HandlerArgsFor<Context, H>, imbl_value::Error> ) -> Result<HandlerArgsFor<Context, H>, imbl_value::Error>
where where
H: HandlerTypes, H: HandlerTypes<InheritedParams = Inherited>,
H::Params: DeserializeOwned, H::Params: DeserializeOwned,
H::InheritedParams: DeserializeOwned,
{ {
let Self { let Self {
context, context,
@@ -52,7 +51,7 @@ impl HandleAnyArgs {
parent_method, parent_method,
method, method,
params: imbl_value::from_value(params.clone())?, params: imbl_value::from_value(params.clone())?,
inherited_params: imbl_value::from_value(inherited.clone())?, inherited_params: inherited,
raw_params: params, raw_params: params,
}) })
} }
@@ -60,8 +59,12 @@ impl HandleAnyArgs {
#[async_trait::async_trait] #[async_trait::async_trait]
pub(crate) trait HandleAny: Send + Sync { pub(crate) trait HandleAny: Send + Sync {
fn handle_sync(&self, handle_args: HandleAnyArgs) -> Result<Value, RpcError>; type Inherited: Send;
async fn handle_async(&self, handle_args: HandleAnyArgs) -> Result<Value, RpcError>; 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( fn metadata(
&self, &self,
method: VecDeque<&'static str>, method: VecDeque<&'static str>,
@@ -71,10 +74,14 @@ pub(crate) trait HandleAny: Send + Sync {
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<T: HandleAny> HandleAny for Arc<T> { 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) 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 self.deref().handle_async(handle_args).await
} }
fn metadata( fn metadata(
@@ -90,13 +97,18 @@ impl<T: HandleAny> HandleAny for Arc<T> {
} }
pub(crate) trait CliBindingsAny { pub(crate) trait CliBindingsAny {
type Inherited;
fn cli_command(&self, ctx_ty: TypeId) -> Command; fn cli_command(&self, ctx_ty: TypeId) -> Command;
fn cli_parse( fn cli_parse(
&self, &self,
matches: &ArgMatches, matches: &ArgMatches,
ctx_ty: TypeId, ctx_ty: TypeId,
) -> Result<(VecDeque<&'static str>, Value), clap::Error>; ) -> 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 { pub trait CliBindings: HandlerTypes {
@@ -172,24 +184,41 @@ where
} }
} }
pub(crate) trait HandleAnyWithCli: HandleAny + CliBindingsAny {} pub(crate) trait HandleAnyWithCli<Inherited>:
impl<T: HandleAny + CliBindingsAny> HandleAnyWithCli for T {} HandleAny<Inherited = Inherited> + CliBindingsAny<Inherited = Inherited>
{
}
impl<Inherited, T: HandleAny<Inherited = Inherited> + CliBindingsAny<Inherited = Inherited>>
HandleAnyWithCli<Inherited> for T
{
}
#[derive(Clone)]
#[allow(private_interfaces)] #[allow(private_interfaces)]
pub enum DynHandler { pub enum DynHandler<Inherited> {
WithoutCli(Arc<dyn HandleAny>), WithoutCli(Arc<dyn HandleAny<Inherited = Inherited>>),
WithCli(Arc<dyn HandleAnyWithCli>), 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] #[async_trait::async_trait]
impl HandleAny for DynHandler { impl<Inherited: Send> HandleAny for DynHandler<Inherited> {
fn handle_sync(&self, handle_args: HandleAnyArgs) -> Result<Value, RpcError> { type Inherited = Inherited;
fn handle_sync(&self, handle_args: HandleAnyArgs<Self::Inherited>) -> Result<Value, RpcError> {
match self { match self {
DynHandler::WithoutCli(h) => h.handle_sync(handle_args), DynHandler::WithoutCli(h) => h.handle_sync(handle_args),
DynHandler::WithCli(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 { match self {
DynHandler::WithoutCli(h) => h.handle_async(handle_args).await, DynHandler::WithoutCli(h) => h.handle_async(handle_args).await,
DynHandler::WithCli(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> impl<H: Handler> HandleAny for AnyHandler<H>
where where
H::Params: DeserializeOwned, H::Params: DeserializeOwned,
H::InheritedParams: DeserializeOwned,
H::Ok: Serialize, H::Ok: Serialize,
RpcError: From<H::Err>, 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( imbl_value::to_value(
&self &self
.0 .0
@@ -321,7 +350,10 @@ where
) )
.map_err(internal_error) .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( imbl_value::to_value(
&self &self
.0 .0
@@ -346,10 +378,10 @@ impl<H: CliBindings> CliBindingsAny for AnyHandler<H>
where where
H: CliBindings, H: CliBindings,
H::Params: DeserializeOwned, H::Params: DeserializeOwned,
H::InheritedParams: DeserializeOwned,
H::Ok: Serialize + DeserializeOwned, H::Ok: Serialize + DeserializeOwned,
RpcError: From<H::Err>, RpcError: From<H::Err>,
{ {
type Inherited = H::InheritedParams;
fn cli_command(&self, ctx_ty: TypeId) -> Command { fn cli_command(&self, ctx_ty: TypeId) -> Command {
self.0.cli_command(ctx_ty) self.0.cli_command(ctx_ty)
} }
@@ -360,7 +392,11 @@ where
) -> Result<(VecDeque<&'static str>, Value), clap::Error> { ) -> Result<(VecDeque<&'static str>, Value), clap::Error> {
self.0.cli_parse(matches, ctx_ty) 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 self.0
.cli_display( .cli_display(
handle_args.downcast::<_, H>().map_err(invalid_params)?, handle_args.downcast::<_, H>().map_err(invalid_params)?,
@@ -373,9 +409,19 @@ where
#[derive(Debug, Clone, Copy, Deserialize, Serialize, Parser)] #[derive(Debug, Clone, Copy, Deserialize, Serialize, Parser)]
pub struct Empty {} pub struct Empty {}
pub(crate) trait OrEmpty<T> {} pub(crate) trait OrEmpty<T> {
impl<T> OrEmpty<T> for T {} fn from_t(t: T) -> Self;
impl<A, B> OrEmpty<Flat<A, B>> for Empty {} }
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)] #[derive(Debug, Clone, Copy, Deserialize, Serialize, Parser)]
pub enum Never {} pub enum Never {}

View File

@@ -4,7 +4,7 @@ use std::sync::Arc;
use clap::{ArgMatches, Command, CommandFactory, FromArgMatches}; use clap::{ArgMatches, Command, CommandFactory, FromArgMatches};
use imbl_value::imbl::{OrdMap, OrdSet}; use imbl_value::imbl::{OrdMap, OrdSet};
use imbl_value::{to_value, Value}; use imbl_value::Value;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use serde::Serialize; use serde::Serialize;
use yajrc::RpcError; use yajrc::RpcError;
@@ -12,33 +12,37 @@ use yajrc::RpcError;
use crate::util::{combine, Flat, PhantomData}; use crate::util::{combine, Flat, PhantomData};
use crate::{ use crate::{
AnyContext, AnyHandler, CliBindings, DynHandler, Empty, HandleAny, HandleAnyArgs, Handler, AnyContext, AnyHandler, CliBindings, DynHandler, Empty, HandleAny, HandleAnyArgs, Handler,
HandlerArgs, HandlerArgsFor, HandlerTypes, IntoContext, OrEmpty, HandlerArgs, HandlerArgsFor, HandlerExt, HandlerTypes, IntoContext, OrEmpty,
}; };
pub trait IntoHandlers: HandlerTypes { pub trait IntoHandlers<Inherited>: HandlerTypes {
fn into_handlers(self) -> impl IntoIterator<Item = (Option<TypeId>, DynHandler)>; 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 where
H: Handler + CliBindings, H: Handler + CliBindings,
H::Params: DeserializeOwned, H::Params: DeserializeOwned,
H::InheritedParams: DeserializeOwned, H::InheritedParams: OrEmpty<Flat<A, B>>,
H::Ok: Serialize + DeserializeOwned, H::Ok: Serialize + DeserializeOwned,
RpcError: From<H::Err>, 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( iter_from_ctx_and_handler(
intersect_type_ids(self.contexts(), <Self as CliBindings>::Context::type_ids()), 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>>, ctx: Option<OrdSet<TypeId>>,
handler: DynHandler, handler: DynHandler<Inherited>,
) -> impl IntoIterator<Item = (Option<TypeId>, DynHandler)> { ) -> impl IntoIterator<Item = (Option<TypeId>, DynHandler<Inherited>)> {
if let Some(ctx) = ctx { if let Some(ctx) = ctx {
itertools::Either::Left(ctx.into_iter().map(Some)) itertools::Either::Left(ctx.into_iter().map(Some))
} else { } else {
@@ -67,13 +71,19 @@ impl<'a> std::borrow::Borrow<Option<&'a str>> for Name {
} }
} }
#[derive(Clone)] pub(crate) struct SubcommandMap<Inherited>(
pub(crate) struct SubcommandMap(pub(crate) OrdMap<Name, OrdMap<Option<TypeId>, DynHandler>>); pub(crate) OrdMap<Name, OrdMap<Option<TypeId>, DynHandler<Inherited>>>,
impl SubcommandMap { );
impl<Inherited> Clone for SubcommandMap<Inherited> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl<Inherited> SubcommandMap<Inherited> {
fn insert( fn insert(
&mut self, &mut self,
name: Option<&'static str>, 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(); let mut for_name = self.0.remove(&name).unwrap_or_default();
for (ctx_ty, handler) in handlers { for (ctx_ty, handler) in handlers {
@@ -82,7 +92,11 @@ impl SubcommandMap {
self.0.insert(Name(name), for_name); 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((name, for_name)) = self.0.get_key_value(&name) {
if let Some(for_ctx) = for_name.get(&Some(ctx_ty)) { if let Some(for_ctx) = for_name.get(&Some(ctx_ty)) {
Some((*name, for_ctx)) Some((*name, for_ctx))
@@ -96,8 +110,8 @@ impl SubcommandMap {
} }
pub struct ParentHandler<Params = Empty, InheritedParams = Empty> { pub struct ParentHandler<Params = Empty, InheritedParams = Empty> {
_phantom: PhantomData<(Params, InheritedParams)>, _phantom: PhantomData<Params>,
pub(crate) subcommands: SubcommandMap, pub(crate) subcommands: SubcommandMap<Flat<Params, InheritedParams>>,
metadata: OrdMap<&'static str, Value>, metadata: OrdMap<&'static str, Value>,
} }
impl<Params, InheritedParams> ParentHandler<Params, InheritedParams> { impl<Params, InheritedParams> ParentHandler<Params, InheritedParams> {
@@ -141,8 +155,7 @@ impl<Params, InheritedParams> ParentHandler<Params, InheritedParams> {
#[allow(private_bounds)] #[allow(private_bounds)]
pub fn subcommand<H>(mut self, name: &'static str, handler: H) -> Self pub fn subcommand<H>(mut self, name: &'static str, handler: H) -> Self
where where
H: IntoHandlers, H: IntoHandlers<Flat<Params, InheritedParams>>,
H::InheritedParams: OrEmpty<Flat<Params, InheritedParams>>,
{ {
self.subcommands self.subcommands
.insert(name.into(), handler.into_handlers()); .insert(name.into(), handler.into_handlers());
@@ -151,8 +164,7 @@ impl<Params, InheritedParams> ParentHandler<Params, InheritedParams> {
#[allow(private_bounds)] #[allow(private_bounds)]
pub fn root_handler<H>(mut self, handler: H) -> Self pub fn root_handler<H>(mut self, handler: H) -> Self
where where
H: IntoHandlers<Params = Empty>, H: IntoHandlers<Flat<Params, InheritedParams>>,
H::InheritedParams: OrEmpty<Flat<Params, InheritedParams>>,
{ {
self.subcommands.insert(None, handler.into_handlers()); self.subcommands.insert(None, handler.into_handlers());
self self
@@ -182,9 +194,9 @@ where
context, context,
mut parent_method, mut parent_method,
mut method, mut method,
params,
inherited_params, inherited_params,
raw_params, raw_params,
..
}: HandlerArgsFor<AnyContext, Self>, }: HandlerArgsFor<AnyContext, Self>,
) -> Result<Self::Ok, Self::Err> { ) -> Result<Self::Ok, Self::Err> {
let cmd = method.pop_front(); let cmd = method.pop_front();
@@ -197,7 +209,7 @@ where
parent_method, parent_method,
method, method,
params: raw_params, params: raw_params,
inherited: to_value(&inherited_params)?, inherited: Flat(params, inherited_params),
}) })
} else { } else {
Err(yajrc::METHOD_NOT_FOUND_ERROR) Err(yajrc::METHOD_NOT_FOUND_ERROR)
@@ -209,9 +221,9 @@ where
context, context,
mut parent_method, mut parent_method,
mut method, mut method,
params,
inherited_params, inherited_params,
raw_params, raw_params,
..
}: HandlerArgsFor<AnyContext, Self>, }: HandlerArgsFor<AnyContext, Self>,
) -> Result<Self::Ok, Self::Err> { ) -> Result<Self::Ok, Self::Err> {
let cmd = method.pop_front(); let cmd = method.pop_front();
@@ -225,7 +237,7 @@ where
parent_method, parent_method,
method, method,
params: raw_params, params: raw_params,
inherited: to_value(&inherited_params)?, inherited: Flat(params, inherited_params),
}) })
.await .await
} else { } else {
@@ -330,9 +342,9 @@ where
context, context,
mut parent_method, mut parent_method,
mut method, mut method,
params,
inherited_params, inherited_params,
raw_params, raw_params,
..
}: HandlerArgsFor<AnyContext, Self>, }: HandlerArgsFor<AnyContext, Self>,
result: Self::Ok, result: Self::Ok,
) -> Result<(), Self::Err> { ) -> Result<(), Self::Err> {
@@ -349,7 +361,7 @@ where
parent_method, parent_method,
method, method,
params: raw_params, params: raw_params,
inherited: to_value(&inherited_params)?, inherited: Flat(params, inherited_params),
}, },
result, result,
) )

View File

@@ -8,7 +8,7 @@ use imbl_value::{InOMap, Value};
use yajrc::{RpcError, RpcMethod}; use yajrc::{RpcError, RpcMethod};
use crate::util::{invalid_request, JobRunner}; 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 GenericRpcMethod = yajrc::GenericRpcMethod<String, Value, Value>;
pub type RpcRequest = yajrc::RpcRequest<GenericRpcMethod>; pub type RpcRequest = yajrc::RpcRequest<GenericRpcMethod>;
@@ -66,7 +66,7 @@ impl<Context: crate::Context> Server<Context> {
parent_method: VecDeque::new(), parent_method: VecDeque::new(),
method: method.ok_or_else(|| yajrc::METHOD_NOT_FOUND_ERROR)?, method: method.ok_or_else(|| yajrc::METHOD_NOT_FOUND_ERROR)?,
params, params,
inherited: Value::Object(InOMap::new()), inherited: crate::Empty {},
}) })
.await .await
} }

View File

@@ -159,7 +159,7 @@ fn make_api() -> ParentHandler {
.subcommand( .subcommand(
"fizz", "fizz",
ParentHandler::<InheritParams>::new().root_handler( ParentHandler::<InheritParams>::new().root_handler(
from_fn(|c: CliContext, _, InheritParams { donde }| { from_fn(|c: CliContext, _: Empty, InheritParams { donde }| {
Ok::<_, RpcError>( Ok::<_, RpcError>(
format!( format!(
"Root Command: Host {host} Donde = {donde}", "Root Command: Host {host} Donde = {donde}",
@@ -174,7 +174,7 @@ fn make_api() -> ParentHandler {
.subcommand( .subcommand(
"error", "error",
ParentHandler::<InheritParams>::new().root_handler( ParentHandler::<InheritParams>::new().root_handler(
from_fn(|c: CliContext, _, InheritParams { donde }| { from_fn(|c: CliContext, _: Empty, InheritParams { donde }| {
Err::<String, _>(RpcError { Err::<String, _>(RpcError {
code: 1, code: 1,
message: "This is an example message".into(), message: "This is an example message".into(),