Skip to content

Commit d61bc41

Browse files
authored
Merge pull request #5864 from Turbo87/remove-obsolete-code
conduit-axum: Remove obsolete code
2 parents 5228d2f + 9080d31 commit d61bc41

File tree

4 files changed

+6
-88
lines changed

4 files changed

+6
-88
lines changed

conduit-axum/src/conduit.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,3 @@ where
7979
Ok(ConduitRequest(request))
8080
}
8181
}
82-
83-
/// A Handler takes a request and returns a response or an error.
84-
/// By default, a bare function implements `Handler`.
85-
pub trait Handler: Sync + Send + 'static {
86-
fn call(&self, request: ConduitRequest) -> HandlerResult;
87-
}
88-
89-
impl<F> Handler for F
90-
where
91-
F: Fn(ConduitRequest) -> HandlerResult + Sync + Send + 'static,
92-
{
93-
fn call(&self, request: ConduitRequest) -> HandlerResult {
94-
(*self)(request)
95-
}
96-
}

conduit-axum/src/fallback.rs

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
use crate::error::ServiceError;
22
use crate::response::AxumResponse;
3-
use crate::{spawn_blocking, ConduitRequest, Handler};
3+
use crate::ConduitRequest;
44

55
use std::collections::BTreeMap;
66
use std::error::Error;
7-
use std::future::Future;
8-
use std::pin::Pin;
9-
use std::sync::Arc;
107

118
use axum::body::{Body, HttpBody};
12-
use axum::extract::{Extension, FromRequest, Path};
13-
use axum::handler::Handler as AxumHandler;
9+
use axum::extract::{Extension, Path};
1410
use axum::response::IntoResponse;
1511
use http::header::CONTENT_LENGTH;
1612
use http::StatusCode;
@@ -23,44 +19,6 @@ use tracing::{error, warn};
2319
/// See the usage section of the README if you plan to use this server in production.
2420
const MAX_CONTENT_LENGTH: u64 = 128 * 1024 * 1024; // 128 MB
2521

26-
#[derive(Debug)]
27-
pub struct ConduitAxumHandler<H>(pub Arc<H>);
28-
29-
impl<H> ConduitAxumHandler<H> {
30-
pub fn wrap(handler: H) -> Self {
31-
Self(Arc::new(handler))
32-
}
33-
}
34-
35-
impl<H> Clone for ConduitAxumHandler<H> {
36-
fn clone(&self) -> Self {
37-
Self(self.0.clone())
38-
}
39-
}
40-
41-
impl<S, H> AxumHandler<((),), S> for ConduitAxumHandler<H>
42-
where
43-
S: Send + Sync + 'static,
44-
H: Handler,
45-
{
46-
type Future = Pin<Box<dyn Future<Output = AxumResponse> + Send>>;
47-
48-
fn call(self, request: Request<Body>, state: S) -> Self::Future {
49-
Box::pin(async move {
50-
let request = match ConduitRequest::from_request(request, &state).await {
51-
Ok(request) => request,
52-
Err(err) => return err,
53-
};
54-
55-
let Self(handler) = self;
56-
spawn_blocking(move || handler.call(request))
57-
.await
58-
.map_err(ServiceError::from)
59-
.into_response()
60-
})
61-
}
62-
}
63-
6422
#[derive(Clone, Debug)]
6523
pub struct ErrorField(pub String);
6624

conduit-axum/src/lib.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
//!
1515
//! ```no_run
1616
//! use axum::routing::get;
17-
//! use conduit_axum::{Handler, ConduitAxumHandler};
17+
//! use axum::response::IntoResponse;
1818
//! use tokio::runtime::Runtime;
1919
//!
2020
//! #[tokio::main]
2121
//! async fn main() {
2222
//! let router = axum::Router::new()
23-
//! .route("/", get(ConduitAxumHandler::wrap(build_conduit_handler())));
23+
//! .route("/", get(handler));
2424
//!
2525
//! let addr = ([127, 0, 0, 1], 12345).into();
2626
//!
@@ -30,22 +30,9 @@
3030
//! .unwrap();
3131
//! }
3232
//!
33-
//! fn build_conduit_handler() -> impl Handler {
33+
//! async fn handler() -> impl IntoResponse {
3434
//! // ...
35-
//! # Endpoint()
3635
//! }
37-
//! #
38-
//! # use std::{error, io};
39-
//! # use axum::body::Bytes;
40-
//! # use axum::response::IntoResponse;
41-
//! # use conduit_axum::{box_error, Response, ConduitRequest, HandlerResult};
42-
//! #
43-
//! # struct Endpoint();
44-
//! # impl Handler for Endpoint {
45-
//! # fn call(&self, _: ConduitRequest) -> HandlerResult {
46-
//! # ().into_response()
47-
//! # }
48-
//! # }
4936
//! ```
5037
5138
mod conduit;
@@ -58,7 +45,5 @@ mod tokio_utils;
5845

5946
pub use conduit::*;
6047
pub use error::ServiceError;
61-
pub use fallback::{
62-
server_error_response, CauseField, ConduitAxumHandler, ErrorField, RequestParamsExt,
63-
};
48+
pub use fallback::{server_error_response, CauseField, ErrorField, RequestParamsExt};
6449
pub use tokio_utils::spawn_blocking;

src/router.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use axum::response::IntoResponse;
22
use axum::routing::{delete, get, post, put};
33
use axum::Router;
4-
use conduit_axum::{ConduitRequest, Handler, HandlerResult};
54

65
use crate::app::AppState;
76
use crate::controllers::*;
@@ -168,15 +167,6 @@ pub fn build_axum_router(state: AppState) -> Router {
168167
.with_state(state)
169168
}
170169

171-
struct C<R>(pub fn(ConduitRequest) -> R);
172-
173-
impl<R: IntoResponse + 'static> Handler for C<R> {
174-
fn call(&self, req: ConduitRequest) -> HandlerResult {
175-
let C(f) = *self;
176-
f(req).into_response()
177-
}
178-
}
179-
180170
#[cfg(test)]
181171
mod tests {
182172
use crate::util::errors::{

0 commit comments

Comments
 (0)