Change Router::with_state and impl Service for Router<()> (#1552)

* Implement `Service` for `Router<(), B>`

* wip

* wip

* fix some tests

* fix examples

* fix doc tests

* clean up docs

* changelog

* fix

* also call `with_state` when converting `MethodRouter` into a `MakeService`

* suggestions from review
This commit is contained in:
David Pedersen
2022-11-24 14:43:10 +00:00
committed by GitHub
parent fde38f6618
commit 0b26411f39
45 changed files with 576 additions and 738 deletions
+3 -3
View File
@@ -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};
@@ -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,
@@ -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
+1 -1
View File
@@ -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());