mirror of https://github.com/fafhrd91/actix-web
update docs and changelog
This commit is contained in:
parent
c1de2a2eb4
commit
4f11d8983a
|
@ -3,7 +3,7 @@
|
|||
## Unreleased - 2021-xx-xx
|
||||
### Added
|
||||
* `impl<T: MessageBody> MessageBody for Pin<Box<T>>`. [#2152]
|
||||
* Helper `body::to_bytes` for async collecting message body into Bytes. [#????]
|
||||
* Helper `body::to_bytes` for async collecting message body into Bytes. [#2158]
|
||||
|
||||
### Changes
|
||||
* The type parameter of `Response` no longer has a default. [#2152]
|
||||
|
@ -23,7 +23,7 @@
|
|||
[#2065]: https://github.com/actix/actix-web/pull/2065
|
||||
[#2148]: https://github.com/actix/actix-web/pull/2148
|
||||
[#2152]: https://github.com/actix/actix-web/pull/2152
|
||||
[#????]: https://github.com/actix/actix-web/pull/????
|
||||
[#2158]: https://github.com/actix/actix-web/pull/2158
|
||||
|
||||
|
||||
## 3.0.0-beta.5 - 2021-04-02
|
||||
|
|
|
@ -22,6 +22,25 @@ pub use self::response_body::ResponseBody;
|
|||
pub use self::size::BodySize;
|
||||
pub use self::sized_stream::SizedStream;
|
||||
|
||||
/// Collects the body produced by a `MessageBody` implementation into `Bytes`.
|
||||
///
|
||||
/// Any errors produced by the body stream are returned immediately.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use actix_http::body::{Body, to_bytes};
|
||||
/// use bytes::Bytes;
|
||||
///
|
||||
/// # async fn test_to_bytes() {
|
||||
/// let body = Body::Empty;
|
||||
/// let bytes = to_bytes(body).await.unwrap();
|
||||
/// assert!(bytes.is_empty());
|
||||
///
|
||||
/// let body = Body::Bytes(Bytes::from_static(b"123"));
|
||||
/// let bytes = to_bytes(body).await.unwrap();
|
||||
/// assert_eq!(bytes, b"123"[..]);
|
||||
/// # }
|
||||
/// ```
|
||||
pub async fn to_bytes(body: impl MessageBody) -> Result<Bytes, crate::Error> {
|
||||
let cap = match body.size() {
|
||||
BodySize::None | BodySize::Empty | BodySize::Sized(0) => return Ok(Bytes::new()),
|
||||
|
|
Loading…
Reference in New Issue