mirror of
https://github.com/tokio-rs/axum.git
synced 2024-12-29 15:49:16 +01:00
Re-export more body utilities (#162)
Useful when implementing `IntoResponse`
This commit is contained in:
parent
b4bdddf9d2
commit
b75b7b0184
3 changed files with 16 additions and 10 deletions
|
@ -1,14 +1,17 @@
|
||||||
//! HTTP body utilities.
|
//! HTTP body utilities.
|
||||||
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use bytes::Bytes;
|
|
||||||
use tower::BoxError;
|
use tower::BoxError;
|
||||||
|
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use http_body::Body as HttpBody;
|
pub use http_body::{Body as HttpBody, Empty, Full};
|
||||||
|
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use hyper::body::Body;
|
pub use hyper::body::Body;
|
||||||
|
|
||||||
|
#[doc(no_inline)]
|
||||||
|
pub use bytes::Bytes;
|
||||||
|
|
||||||
/// A boxed [`Body`] trait object.
|
/// A boxed [`Body`] trait object.
|
||||||
///
|
///
|
||||||
/// This is used in axum as the response body type for applications. Its
|
/// This is used in axum as the response body type for applications. Its
|
||||||
|
|
|
@ -82,7 +82,7 @@ where
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use axum::{prelude::*, extract::NestedUri, http::Uri};
|
/// use axum::{prelude::*, routing::nest, extract::NestedUri, http::Uri};
|
||||||
///
|
///
|
||||||
/// let api_routes = route(
|
/// let api_routes = route(
|
||||||
/// "/users",
|
/// "/users",
|
||||||
|
|
|
@ -89,17 +89,20 @@ pub trait IntoResponse {
|
||||||
/// Unless you're implementing this trait for a custom body type, these are
|
/// Unless you're implementing this trait for a custom body type, these are
|
||||||
/// some common types you can use:
|
/// some common types you can use:
|
||||||
///
|
///
|
||||||
/// - [`hyper::Body`]: A good default that supports most use cases.
|
/// - [`hyper::Body`]: A good default that supports most use cases. This is
|
||||||
/// - [`http_body::Empty<Bytes>`]: When you know your response is always
|
/// also re-exported as [`axum::body::Body`].
|
||||||
|
/// - [`axum::body::Empty<Bytes>`]: When you know your response is always
|
||||||
/// empty.
|
/// empty.
|
||||||
/// - [`http_body::Full<Bytes>`]: When you know your response always
|
/// - [`axum::body::Full<Bytes>`]: When you know your response always
|
||||||
/// contains exactly one chunk.
|
/// contains exactly one chunk.
|
||||||
/// - [`BoxBody`]: If you need to unify multiple body types into one, or
|
/// - [`axum::body::BoxBody`]: If you need to unify multiple body types into
|
||||||
/// return a body type that cannot be named. Can be created with
|
/// one, or return a body type that cannot be named. Can be created with
|
||||||
/// [`box_body`].
|
/// [`box_body`].
|
||||||
///
|
///
|
||||||
/// [`http_body::Empty<Bytes>`]: http_body::Empty
|
/// [`axum::body::Body`]: crate::body::Body
|
||||||
/// [`http_body::Full<Bytes>`]: http_body::Full
|
/// [`axum::body::Empty<Bytes>`]: crate::body::Empty
|
||||||
|
/// [`axum::body::Full<Bytes>`]: crate::body::Full
|
||||||
|
/// [`axum::body::BoxBody`]: crate::body::BoxBody
|
||||||
type Body: http_body::Body<Data = Bytes, Error = Self::BodyError> + Send + Sync + 'static;
|
type Body: http_body::Body<Data = Bytes, Error = Self::BodyError> + Send + Sync + 'static;
|
||||||
|
|
||||||
/// The error type `Self::Body` might generate.
|
/// The error type `Self::Body` might generate.
|
||||||
|
|
Loading…
Reference in a new issue