mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-27 00:00:24 +02:00
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:
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user