Function actix_http::body::to_bytes [−][src]
pub async fn to_bytes<B: MessageBody>(body: B) -> Result<Bytes, B::Error>
Expand description
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::{AnyBody, to_bytes};
use bytes::Bytes;
let body = AnyBody::none();
let bytes = to_bytes(body).await.unwrap();
assert!(bytes.is_empty());
let body = AnyBody::copy_from_slice(b"123");
let bytes = to_bytes(body).await.unwrap();
assert_eq!(bytes, b"123"[..]);