undo extra for with_call_remote

This commit is contained in:
Aiden McClelland
2024-05-03 14:51:14 -06:00
parent e2d05fd93e
commit 02e6571866
2 changed files with 14 additions and 20 deletions

View File

@@ -40,7 +40,7 @@ pub trait HandlerExt: Handler + Sized {
) -> InheritanceHandler<Params, InheritedParams, Self, F> ) -> InheritanceHandler<Params, InheritedParams, Self, F>
where where
F: Fn(Params, InheritedParams) -> Self::InheritedParams; F: Fn(Params, InheritedParams) -> Self::InheritedParams;
fn with_call_remote<Context, Extra>(self) -> RemoteCaller<Context, Self, Extra>; fn with_call_remote<Context>(self) -> RemoteCaller<Context, Self>;
} }
impl<T: Handler + Sized> HandlerExt for T { impl<T: Handler + Sized> HandlerExt for T {
@@ -90,7 +90,7 @@ impl<T: Handler + Sized> HandlerExt for T {
inherit: f, inherit: f,
} }
} }
fn with_call_remote<Context, Extra>(self) -> RemoteCaller<Context, Self, Extra> { fn with_call_remote<Context>(self) -> RemoteCaller<Context, Self> {
RemoteCaller { RemoteCaller {
_phantom: PhantomData::new(), _phantom: PhantomData::new(),
handler: self, handler: self,
@@ -452,11 +452,11 @@ where
} }
} }
pub struct RemoteCaller<Context, H, Extra = Empty> { pub struct RemoteCaller<Context, H> {
_phantom: PhantomData<(Context, Extra)>, _phantom: PhantomData<Context>,
handler: H, handler: H,
} }
impl<Context, H: Clone, Extra> Clone for RemoteCaller<Context, H, Extra> { impl<Context, H: Clone> Clone for RemoteCaller<Context, H> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
_phantom: PhantomData::new(), _phantom: PhantomData::new(),
@@ -464,31 +464,29 @@ impl<Context, H: Clone, Extra> Clone for RemoteCaller<Context, H, Extra> {
} }
} }
} }
impl<Context, H: Debug, Extra> Debug for RemoteCaller<Context, H, Extra> { impl<Context, H: Debug> Debug for RemoteCaller<Context, H> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("RemoteCaller").field(&self.handler).finish() f.debug_tuple("RemoteCaller").field(&self.handler).finish()
} }
} }
impl<Context, H, Extra> HandlerTypes for RemoteCaller<Context, H, Extra> impl<Context, H> HandlerTypes for RemoteCaller<Context, H>
where where
H: HandlerTypes, H: HandlerTypes,
Extra: Send + Sync + 'static,
{ {
type Params = Flat<H::Params, Extra>; type Params = H::Params;
type InheritedParams = H::InheritedParams; type InheritedParams = H::InheritedParams;
type Ok = H::Ok; type Ok = H::Ok;
type Err = H::Err; type Err = H::Err;
} }
impl<Context, H, Extra> Handler for RemoteCaller<Context, H, Extra> impl<Context, H> Handler for RemoteCaller<Context, H>
where where
Context: CallRemote<H::Context, Extra>, Context: CallRemote<H::Context>,
H: Handler, H: Handler,
H::Params: Serialize, H::Params: Serialize,
H::InheritedParams: Serialize, H::InheritedParams: Serialize,
H::Ok: DeserializeOwned, H::Ok: DeserializeOwned,
H::Err: From<RpcError>, H::Err: From<RpcError>,
Extra: Serialize + Send + Sync + 'static,
{ {
type Context = EitherContext<Context, H::Context>; type Context = EitherContext<Context, H::Context>;
async fn handle_async( async fn handle_async(
@@ -497,7 +495,7 @@ where
context, context,
parent_method, parent_method,
method, method,
params: Flat(params, extra), params,
inherited_params, inherited_params,
raw_params, raw_params,
}: HandlerArgsFor<Self::Context, Self>, }: HandlerArgsFor<Self::Context, Self>,
@@ -506,11 +504,7 @@ where
EitherContext::C1(context) => { EitherContext::C1(context) => {
let full_method = parent_method.into_iter().chain(method).collect::<Vec<_>>(); let full_method = parent_method.into_iter().chain(method).collect::<Vec<_>>();
match context match context
.call_remote( .call_remote(&full_method.join("."), raw_params, Empty {})
&full_method.join("."),
without(raw_params, &extra).map_err(invalid_params)?,
extra,
)
.await .await
{ {
Ok(a) => imbl_value::from_value(a) Ok(a) => imbl_value::from_value(a)
@@ -559,7 +553,7 @@ where
context, context,
parent_method, parent_method,
method, method,
params: Flat(params, _), params,
inherited_params, inherited_params,
raw_params, raw_params,
}: HandlerArgsFor<Self::Context, Self>, }: HandlerArgsFor<Self::Context, Self>,

View File

@@ -129,7 +129,7 @@ fn make_api() -> ParentHandler {
)) ))
}, },
) )
.with_call_remote::<CliContext, Empty>(), .with_call_remote::<CliContext>(),
) )
.subcommand( .subcommand(
"hello", "hello",