mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-25 00:00:23 +02:00
Type safe state inheritance (#1532)
* Make state type safe * fix examples * remove unnecessary `#[track_caller]`s * Router::into_service -> Router::with_state * fixup docs * macro docs * add missing docs * fix examples * format * changelog * Update trybuild tests * Make sure fallbacks are still inherited for opaque services (#1540) * Document nesting routers with different state * fix leftover conflicts
This commit is contained in:
@@ -34,13 +34,14 @@ use tower_layer::Layer;
|
||||
/// http::Request,
|
||||
/// };
|
||||
///
|
||||
/// let router = Router::new()
|
||||
/// let app = Router::new()
|
||||
/// .route(
|
||||
/// "/",
|
||||
/// // even with `DefaultBodyLimit` the request body is still just `Body`
|
||||
/// post(|request: Request<Body>| async {}),
|
||||
/// )
|
||||
/// .layer(DefaultBodyLimit::max(1024));
|
||||
/// # let _: Router<(), _> = app;
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
@@ -48,7 +49,7 @@ use tower_layer::Layer;
|
||||
/// use tower_http::limit::RequestBodyLimitLayer;
|
||||
/// use http_body::Limited;
|
||||
///
|
||||
/// let router = Router::new()
|
||||
/// let app = Router::new()
|
||||
/// .route(
|
||||
/// "/",
|
||||
/// // `RequestBodyLimitLayer` changes the request body type to `Limited<Body>`
|
||||
@@ -56,6 +57,7 @@ use tower_layer::Layer;
|
||||
/// post(|request: Request<Limited<Body>>| async {}),
|
||||
/// )
|
||||
/// .layer(RequestBodyLimitLayer::new(1024));
|
||||
/// # let _: Router<(), _> = app;
|
||||
/// ```
|
||||
///
|
||||
/// In general using `DefaultBodyLimit` is recommended but if you need to use third party
|
||||
@@ -102,7 +104,7 @@ impl DefaultBodyLimit {
|
||||
/// use tower_http::limit::RequestBodyLimitLayer;
|
||||
/// use http_body::Limited;
|
||||
///
|
||||
/// let app: Router<_, Limited<Body>> = Router::new()
|
||||
/// let app: Router<(), Limited<Body>> = Router::new()
|
||||
/// .route("/", get(|body: Bytes| async {}))
|
||||
/// // Disable the default limit
|
||||
/// .layer(DefaultBodyLimit::disable())
|
||||
@@ -138,7 +140,7 @@ impl DefaultBodyLimit {
|
||||
/// use tower_http::limit::RequestBodyLimitLayer;
|
||||
/// use http_body::Limited;
|
||||
///
|
||||
/// let app: Router<_, Limited<Body>> = Router::new()
|
||||
/// let app: Router<(), Limited<Body>> = Router::new()
|
||||
/// .route("/", get(|body: Bytes| async {}))
|
||||
/// // Replace the default of 2MB with 1024 bytes.
|
||||
/// .layer(DefaultBodyLimit::max(1024));
|
||||
|
||||
Reference in New Issue
Block a user