Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpdrsn committed Nov 23, 2022
1 parent d51d477 commit 7dac86f
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 558 deletions.
6 changes: 3 additions & 3 deletions axum-extra/src/routing/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<B> From<Resource<B>> for Router<B> {
mod tests {
#[allow(unused_imports)]
use super::*;
use axum::{extract::Path, http::Method, routing::RouterService, Router};
use axum::{extract::Path, http::Method, Router};
use http::Request;
use tower::{Service, ServiceExt};

Expand All @@ -162,7 +162,7 @@ mod tests {
.update(|Path(id): Path<u64>| async move { format!("users#update id={}", id) })
.destroy(|Path(id): Path<u64>| async move { format!("users#destroy id={}", id) });

let mut app = Router::new().merge(users).into_service();
let mut app = Router::new().merge(users);

assert_eq!(
call_route(&mut app, Method::GET, "/users").await,
Expand Down Expand Up @@ -205,7 +205,7 @@ mod tests {
);
}

async fn call_route(app: &mut RouterService, method: Method, uri: &str) -> String {
async fn call_route(app: &mut Router, method: Method, uri: &str) -> String {
let res = app
.ready()
.await
Expand Down
2 changes: 1 addition & 1 deletion axum-extra/src/routing/spa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ mod tests {

#[allow(dead_code)]
fn works_with_router_with_state() {
let _: axum::RouterService = Router::new()
let _: Router = Router::new()
.merge(SpaRouter::new("/assets", "test_files"))
.route("/", get(|_: axum::extract::State<String>| async {}))
.with_state(String::new());
Expand Down
43 changes: 16 additions & 27 deletions axum/benches/benches.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use axum::{
extract::State,
routing::{get, post},
Extension, Json, Router, RouterService, Server,
Extension, Json, Router, Server,
};
use hyper::server::conn::AddrIncoming;
use serde::{Deserialize, Serialize};
Expand All @@ -17,13 +17,9 @@ fn main() {
ensure_rewrk_is_installed();
}

benchmark("minimal").run(|| Router::new().into_service());
benchmark("minimal").run(Router::new);

benchmark("basic").run(|| {
Router::new()
.route("/", get(|| async { "Hello, World!" }))
.into_service()
});
benchmark("basic").run(|| Router::new().route("/", get(|| async { "Hello, World!" })));

benchmark("routing").path("/foo/bar/baz").run(|| {
let mut app = Router::new();
Expand All @@ -34,32 +30,26 @@ fn main() {
}
}
}
app.route("/foo/bar/baz", get(|| async {})).into_service()
app.route("/foo/bar/baz", get(|| async {}))
});

benchmark("receive-json")
.method("post")
.headers(&[("content-type", "application/json")])
.body(r#"{"n": 123, "s": "hi there", "b": false}"#)
.run(|| {
Router::new()
.route("/", post(|_: Json<Payload>| async {}))
.into_service()
});
.run(|| Router::new().route("/", post(|_: Json<Payload>| async {})));

benchmark("send-json").run(|| {
Router::new()
.route(
"/",
get(|| async {
Json(Payload {
n: 123,
s: "hi there".to_owned(),
b: false,
})
}),
)
.into_service()
Router::new().route(
"/",
get(|| async {
Json(Payload {
n: 123,
s: "hi there".to_owned(),
b: false,
})
}),
)
});

let state = AppState {
Expand All @@ -75,7 +65,6 @@ fn main() {
Router::new()
.route("/", get(|_: Extension<AppState>| async {}))
.layer(Extension(state.clone()))
.into_service()
});

benchmark("state").run(|| {
Expand Down Expand Up @@ -133,7 +122,7 @@ impl BenchmarkBuilder {

fn run<F>(self, f: F)
where
F: FnOnce() -> RouterService,
F: FnOnce() -> Router<()>,
{
// support only running some benchmarks with
// ```
Expand Down
8 changes: 4 additions & 4 deletions axum/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ where
where
H: Handler<T, S, B>,
T: 'static,
B: HttpBody,
{
Self(Box::new(MakeErasedHandler {
handler,
Expand Down Expand Up @@ -98,7 +99,7 @@ impl<H, S, B> ErasedIntoRoute<S, B, Infallible> for MakeErasedHandler<H, S, B>
where
H: Clone + Send + 'static,
S: 'static,
B: 'static,
B: HttpBody + 'static,
{
fn clone_box(&self) -> Box<dyn ErasedIntoRoute<S, B, Infallible>> {
Box::new(self.clone())
Expand All @@ -113,7 +114,7 @@ where
request: Request<B>,
state: S,
) -> RouteFuture<B, Infallible> {
todo!()
self.into_route(state).call(request)
}
}

Expand Down Expand Up @@ -193,8 +194,7 @@ where
}

fn call_with_state(self: Box<Self>, request: Request<B2>, state: S) -> RouteFuture<B2, E2> {
let route = (self.layer)(self.inner.into_route(state));
route.call(request)
(self.layer)(self.inner.into_route(state)).call(request)
}
}

Expand Down
4 changes: 2 additions & 2 deletions axum/src/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ mod tests {
format!("you said: {}", body)
}

let client = TestClient::from_service(handle.into_service());
let client = TestClient::new(handle.into_service());

let res = client.post("/").body("hi there!").send().await;
assert_eq!(res.status(), StatusCode::OK);
Expand All @@ -381,7 +381,7 @@ mod tests {
.layer(MapRequestBodyLayer::new(body::boxed))
.with_state("foo");

let client = TestClient::from_service(svc);
let client = TestClient::new(svc);
let res = client.get("/").send().await;
assert_eq!(res.text().await, "foo");
}
Expand Down
2 changes: 1 addition & 1 deletion axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ pub use self::extension::Extension;
#[cfg(feature = "json")]
pub use self::json::Json;
#[doc(inline)]
pub use self::routing::{Router, RouterService};
pub use self::routing::Router;

#[doc(inline)]
#[cfg(feature = "headers")]
Expand Down
1 change: 0 additions & 1 deletion axum/src/middleware/from_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ mod tests {
.layer(from_fn(insert_header));

let res = app
.into_service()
.oneshot(Request::builder().uri("/").body(Body::empty()).unwrap())
.await
.unwrap();
Expand Down

0 comments on commit 7dac86f

Please sign in to comment.