Function actix_web::body::to_bytes

source ·
pub async fn to_bytes<B>(body: B) -> Result<Bytes, <B as MessageBody>::Error>
where B: MessageBody,
Expand description

Collects all the bytes produced by body.

Any errors produced by the body stream are returned immediately.

Consider using to_bytes_limited instead to protect against memory exhaustion.

§Examples

use actix_http::body::{self, to_bytes};
use bytes::Bytes;

let body = body::None::new();
let bytes = to_bytes(body).await.unwrap();
assert!(bytes.is_empty());

let body = Bytes::from_static(b"123");
let bytes = to_bytes(body).await.unwrap();
assert_eq!(bytes, "123");