From 85144f1f70d3f0be48cd22ceef31df27fe154c03 Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Sat, 17 Feb 2024 18:24:32 -0700 Subject: [PATCH] thread through inherited params --- rpc-toolkit/src/cli.rs | 4 +++- rpc-toolkit/src/handler/mod.rs | 4 +++- rpc-toolkit/src/handler/parent.rs | 10 ++++++++-- rpc-toolkit/src/server/mod.rs | 3 ++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/rpc-toolkit/src/cli.rs b/rpc-toolkit/src/cli.rs index 4581bef..dd98ca9 100644 --- a/rpc-toolkit/src/cli.rs +++ b/rpc-toolkit/src/cli.rs @@ -3,7 +3,7 @@ use std::collections::VecDeque; use std::ffi::OsString; use clap::{CommandFactory, FromArgMatches}; -use imbl_value::Value; +use imbl_value::{InOMap, Value}; use reqwest::header::{ACCEPT, CONTENT_LENGTH, CONTENT_TYPE}; use reqwest::{Client, Method}; use serde::de::DeserializeOwned; @@ -67,6 +67,7 @@ impl parent_method: VecDeque::new(), method: method.clone(), params: params.clone(), + inherited: Value::Object(InOMap::new()), })?; root_handler.cli_display( HandleAnyArgs { @@ -74,6 +75,7 @@ impl parent_method: VecDeque::new(), method, params, + inherited: Value::Object(InOMap::new()), }, res, )?; diff --git a/rpc-toolkit/src/handler/mod.rs b/rpc-toolkit/src/handler/mod.rs index 9e3ebb2..51e5a66 100644 --- a/rpc-toolkit/src/handler/mod.rs +++ b/rpc-toolkit/src/handler/mod.rs @@ -26,6 +26,7 @@ pub(crate) struct HandleAnyArgs { pub(crate) parent_method: VecDeque<&'static str>, pub(crate) method: VecDeque<&'static str>, pub(crate) params: Value, + pub(crate) inherited: Value, } impl HandleAnyArgs { fn downcast( @@ -41,6 +42,7 @@ impl HandleAnyArgs { parent_method, method, params, + inherited, } = self; Ok(HandlerArgs { context: Context::downcast(context).map_err(|_| imbl_value::Error { @@ -50,7 +52,7 @@ impl HandleAnyArgs { parent_method, method, params: imbl_value::from_value(params.clone())?, - inherited_params: imbl_value::from_value(params.clone())?, + inherited_params: imbl_value::from_value(inherited.clone())?, raw_params: params, }) } diff --git a/rpc-toolkit/src/handler/parent.rs b/rpc-toolkit/src/handler/parent.rs index 381ca2d..04fc49d 100644 --- a/rpc-toolkit/src/handler/parent.rs +++ b/rpc-toolkit/src/handler/parent.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use clap::{ArgMatches, Command, CommandFactory, FromArgMatches}; use imbl_value::imbl::{OrdMap, OrdSet}; -use imbl_value::Value; +use imbl_value::{to_value, Value}; use serde::de::DeserializeOwned; use serde::Serialize; use yajrc::RpcError; @@ -172,7 +172,7 @@ where #[async_trait::async_trait] impl Handler for ParentHandler where - Params: Serialize + Send + Sync + 'static, + Params: Send + Sync + 'static, InheritedParams: Serialize + Send + Sync + 'static, { type Context = AnyContext; @@ -182,6 +182,7 @@ where context, mut parent_method, mut method, + inherited_params, raw_params, .. }: HandlerArgsFor, @@ -196,6 +197,7 @@ where parent_method, method, params: raw_params, + inherited: to_value(&inherited_params)?, }) } else { Err(yajrc::METHOD_NOT_FOUND_ERROR) @@ -207,6 +209,7 @@ where context, mut parent_method, mut method, + inherited_params, raw_params, .. }: HandlerArgsFor, @@ -222,6 +225,7 @@ where parent_method, method, params: raw_params, + inherited: to_value(&inherited_params)?, }) .await } else { @@ -326,6 +330,7 @@ where context, mut parent_method, mut method, + inherited_params, raw_params, .. }: HandlerArgsFor, @@ -344,6 +349,7 @@ where parent_method, method, params: raw_params, + inherited: to_value(&inherited_params)?, }, result, ) diff --git a/rpc-toolkit/src/server/mod.rs b/rpc-toolkit/src/server/mod.rs index 91c7fcb..4dbf590 100644 --- a/rpc-toolkit/src/server/mod.rs +++ b/rpc-toolkit/src/server/mod.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use futures::future::{join_all, BoxFuture}; use futures::{Future, FutureExt, Stream, StreamExt}; -use imbl_value::Value; +use imbl_value::{InOMap, Value}; use yajrc::{RpcError, RpcMethod}; use crate::util::{invalid_request, JobRunner}; @@ -66,6 +66,7 @@ impl Server { parent_method: VecDeque::new(), method: method.ok_or_else(|| yajrc::METHOD_NOT_FOUND_ERROR)?, params, + inherited: Value::Object(InOMap::new()), }) .await }