From 45fc342774b0a28d27499ee7fd517f6290f220e8 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 30 Sep 2024 11:58:50 -0400 Subject: [PATCH] fix: dep spec for axum feature --- crates/json-rpc-router/src/lib.rs | 8 +++++++- crates/json-rpc/Cargo.toml | 2 +- crates/json-rpc/src/support/axum.rs | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/json-rpc-router/src/lib.rs b/crates/json-rpc-router/src/lib.rs index 9b7837e3a08..fedaaa18727 100644 --- a/crates/json-rpc-router/src/lib.rs +++ b/crates/json-rpc-router/src/lib.rs @@ -29,11 +29,17 @@ use tower::{util::BoxCloneService, Service}; pub type Route = BoxCloneService, ResponsePayload, E>; /// A JSON-RPC router. -#[derive(Clone)] +#[must_use = "Routers do nothing unless served."] pub struct Router { inner: Arc>, } +impl Clone for Router { + fn clone(&self) -> Self { + Self { inner: Arc::clone(&self.inner) } + } +} + impl Router { /// Call a method on the router. pub async fn call_with_state(&self, req: PartiallySerializedRequest, state: S) -> Response { diff --git a/crates/json-rpc/Cargo.toml b/crates/json-rpc/Cargo.toml index 552992835b0..04aede78e94 100644 --- a/crates/json-rpc/Cargo.toml +++ b/crates/json-rpc/Cargo.toml @@ -30,4 +30,4 @@ async-trait = { workspace = true, optional = true } axum = { version = "0.7.6", features = ["json"], optional = true } [features] -axum = ["dep:axum"] +axum = ["dep:axum", "dep:async-trait"] diff --git a/crates/json-rpc/src/support/axum.rs b/crates/json-rpc/src/support/axum.rs index b5cb9e64c2a..8d5f2a33b4c 100644 --- a/crates/json-rpc/src/support/axum.rs +++ b/crates/json-rpc/src/support/axum.rs @@ -3,7 +3,7 @@ use axum::extract; impl From for Response<(), ()> { fn from(value: extract::rejection::JsonRejection) -> Self { - Response { + Self { id: Id::None, payload: ResponsePayload::Failure(ErrorPayload { code: -32600, @@ -34,7 +34,7 @@ where type Rejection = Response<(), ()>; async fn from_request(req: extract::Request, state: &S) -> Result { - let json = extract::Json::>::from_request(req, state).await?; + let json = extract::Json::::from_request(req, state).await?; Ok(json.0) }