Function ajars_actix_web::actix_web::body::to_bytes [−]
pub async fn to_bytes<B>(body: B) -> Result<Bytes, <B as MessageBody>::Error> where
B: MessageBody,
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::{Body, to_bytes}; use bytes::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"[..]);