Skip to content

Router::route_service() example code is out of date #2536

@jwodder

Description

@jwodder

The current documentation for axum::Router::route_service() has an example that contains the following lines:

        // Services whose response body is not `axum::body::BoxBody`
        // can be wrapped in `axum::routing::any_service` (or one of the other routing filters)
        // to have the response body mapped
        any_service(service_fn(|_: Request| async {
            let res = Response::new(Body::from("Hi from `GET /`"));
            Ok::<_, Infallible>(res)
        }))

        ...

        // This service's response body is `axum::body::BoxBody` so
        // it can be routed to directly.
        service_fn(|req: Request| async move {
            let body = Body::from(format!("Hi from `{} /foo`", req.method()));
            let res = Response::new(body);
            Ok::<_, Infallible>(res)
        })

However, despite what the comments in the code say, both responses appear to have axum::body::Body as their bodies, and there is currently no axum::body::BoxBody in the crate. I assume that BoxBody was removed in an earlier version and the example was only partially updated, but that just raises the question: What is any_service() good for now?

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-docsTopic: documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions