Skip to content

Commit

Permalink
fix: dep spec for axum feature
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich committed Oct 13, 2024
1 parent 2a13d6c commit 45fc342
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion crates/json-rpc-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ use tower::{util::BoxCloneService, Service};
pub type Route<E = Infallible> = BoxCloneService<Box<RawValue>, ResponsePayload, E>;

/// A JSON-RPC router.
#[derive(Clone)]
#[must_use = "Routers do nothing unless served."]
pub struct Router<S> {
inner: Arc<RouterInner<S>>,
}

impl<S> Clone for Router<S> {
fn clone(&self) -> Self {
Self { inner: Arc::clone(&self.inner) }
}
}

impl<S> Router<S> {
/// Call a method on the router.
pub async fn call_with_state(&self, req: PartiallySerializedRequest, state: S) -> Response {
Expand Down
2 changes: 1 addition & 1 deletion crates/json-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
4 changes: 2 additions & 2 deletions crates/json-rpc/src/support/axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use axum::extract;

impl From<extract::rejection::JsonRejection> for Response<(), ()> {
fn from(value: extract::rejection::JsonRejection) -> Self {
Response {
Self {
id: Id::None,
payload: ResponsePayload::Failure(ErrorPayload {
code: -32600,
Expand Down Expand Up @@ -34,7 +34,7 @@ where
type Rejection = Response<(), ()>;

async fn from_request(req: extract::Request, state: &S) -> Result<Self, Self::Rejection> {
let json = extract::Json::<Request<Params>>::from_request(req, state).await?;
let json = extract::Json::<Self>::from_request(req, state).await?;

Ok(json.0)
}
Expand Down

0 comments on commit 45fc342

Please sign in to comment.