From 33229337a41806cf0712296c7d8e2229ea31118b Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Fri, 3 May 2024 13:49:31 -0600 Subject: [PATCH] add Extra to CallRemoteHandler --- src/cli.rs | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 9e0c993..9de0e55 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -13,7 +13,7 @@ use tokio::io::{AsyncBufReadExt, AsyncRead, AsyncWrite, AsyncWriteExt, BufReader use url::Url; use yajrc::{Id, RpcError}; -use crate::util::{internal_error, parse_error, PhantomData}; +use crate::util::{internal_error, invalid_params, parse_error, without, Flat, PhantomData}; use crate::{ AnyHandler, CliBindingsAny, DynHandler, Empty, HandleAny, HandleAnyArgs, Handler, HandlerArgs, HandlerArgsFor, HandlerTypes, IntoContext, Name, ParentHandler, PrintCliResult, @@ -172,11 +172,11 @@ pub async fn call_remote_socket( .result } -struct CallRemoteHandler { - _phantom: PhantomData, +pub struct CallRemoteHandler { + _phantom: PhantomData<(Context, Extra)>, handler: RemoteHandler, } -impl CallRemoteHandler { +impl CallRemoteHandler { pub fn new(handler: RemoteHandler) -> Self { Self { _phantom: PhantomData::new(), @@ -184,7 +184,9 @@ impl CallRemoteHandler { } } } -impl Clone for CallRemoteHandler { +impl Clone + for CallRemoteHandler +{ fn clone(&self) -> Self { Self { _phantom: PhantomData::new(), @@ -192,34 +194,39 @@ impl Clone for CallRemoteHandler std::fmt::Debug for CallRemoteHandler { +impl std::fmt::Debug + for CallRemoteHandler +{ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_tuple("CallRemoteHandler").finish() } } -impl HandlerTypes for CallRemoteHandler +impl HandlerTypes + for CallRemoteHandler where RemoteHandler: HandlerTypes, RemoteHandler::Params: Serialize, RemoteHandler::InheritedParams: Serialize, RemoteHandler::Ok: DeserializeOwned, RemoteHandler::Err: From, + Extra: Send + Sync + 'static, { - type Params = RemoteHandler::Params; + type Params = Flat; type InheritedParams = RemoteHandler::InheritedParams; type Ok = RemoteHandler::Ok; type Err = RemoteHandler::Err; } -impl Handler for CallRemoteHandler +impl Handler for CallRemoteHandler where - Context: CallRemote, + Context: CallRemote, RemoteHandler: Handler, RemoteHandler::Params: Serialize, RemoteHandler::InheritedParams: Serialize, RemoteHandler::Ok: DeserializeOwned, RemoteHandler::Err: From, + Extra: Serialize + Send + Sync + 'static, { type Context = Context; async fn handle_async( @@ -235,8 +242,9 @@ where .context .call_remote( &full_method.join("."), - handle_args.raw_params.clone(), - Empty {}, + without(handle_args.raw_params.clone(), &handle_args.params.1) + .map_err(invalid_params)?, + handle_args.params.1, ) .await { @@ -247,7 +255,8 @@ where } } } -impl PrintCliResult for CallRemoteHandler +impl PrintCliResult + for CallRemoteHandler where Context: CallRemote, RemoteHandler: PrintCliResult, @@ -255,6 +264,7 @@ where RemoteHandler::InheritedParams: Serialize, RemoteHandler::Ok: DeserializeOwned, RemoteHandler::Err: From, + Extra: Send + Sync + 'static, { type Context = Context; fn print( @@ -274,7 +284,7 @@ where context, parent_method, method, - params, + params: params.0, inherited_params, raw_params, },