From b75b7b0184f5a249cee8cd9fd4970c25c28bc7a5 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Sun, 8 Aug 2021 16:41:17 +0200 Subject: [PATCH] Re-export more body utilities (#162) Useful when implementing `IntoResponse` --- src/body.rs | 7 +++++-- src/extract/request_parts.rs | 2 +- src/response.rs | 17 ++++++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/body.rs b/src/body.rs index 552f9802..677af2a7 100644 --- a/src/body.rs +++ b/src/body.rs @@ -1,14 +1,17 @@ //! HTTP body utilities. use crate::Error; -use bytes::Bytes; use tower::BoxError; #[doc(no_inline)] -pub use http_body::Body as HttpBody; +pub use http_body::{Body as HttpBody, Empty, Full}; + #[doc(no_inline)] pub use hyper::body::Body; +#[doc(no_inline)] +pub use bytes::Bytes; + /// A boxed [`Body`] trait object. /// /// This is used in axum as the response body type for applications. Its diff --git a/src/extract/request_parts.rs b/src/extract/request_parts.rs index e79a7e86..fbc83d87 100644 --- a/src/extract/request_parts.rs +++ b/src/extract/request_parts.rs @@ -82,7 +82,7 @@ where /// # Example /// /// ``` -/// use axum::{prelude::*, extract::NestedUri, http::Uri}; +/// use axum::{prelude::*, routing::nest, extract::NestedUri, http::Uri}; /// /// let api_routes = route( /// "/users", diff --git a/src/response.rs b/src/response.rs index 4c121dcf..0c194310 100644 --- a/src/response.rs +++ b/src/response.rs @@ -89,17 +89,20 @@ pub trait IntoResponse { /// Unless you're implementing this trait for a custom body type, these are /// some common types you can use: /// - /// - [`hyper::Body`]: A good default that supports most use cases. - /// - [`http_body::Empty`]: When you know your response is always + /// - [`hyper::Body`]: A good default that supports most use cases. This is + /// also re-exported as [`axum::body::Body`]. + /// - [`axum::body::Empty`]: When you know your response is always /// empty. - /// - [`http_body::Full`]: When you know your response always + /// - [`axum::body::Full`]: When you know your response always /// contains exactly one chunk. - /// - [`BoxBody`]: If you need to unify multiple body types into one, or - /// return a body type that cannot be named. Can be created with + /// - [`axum::body::BoxBody`]: If you need to unify multiple body types into + /// one, or return a body type that cannot be named. Can be created with /// [`box_body`]. /// - /// [`http_body::Empty`]: http_body::Empty - /// [`http_body::Full`]: http_body::Full + /// [`axum::body::Body`]: crate::body::Body + /// [`axum::body::Empty`]: crate::body::Empty + /// [`axum::body::Full`]: crate::body::Full + /// [`axum::body::BoxBody`]: crate::body::BoxBody type Body: http_body::Body + Send + Sync + 'static; /// The error type `Self::Body` might generate.