expression
Hyper body: collect a known small body
Hyper 1.x separates HTTP messages from the body implementation. Full provides an already available byte buffer; collect awaits all frames and to_bytes produces the collected data. Use this only for known-small or bounded bodies. In-memory fixture; no external connection. Expected stdout (not executed): pear Common mistake: Collecting an untrusted unlimited response into memory.
Formal Syntax & Structure
rust syntaxrust
Full::new(bytes).collect().await?.to_bytes()Working Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { use hyper::body::Bytes; use http_body_util::{Full, BodyExt}; let body = Full::new(Bytes::from_static(b"pear")); let bytes = body.collect().await.unwrap().to_bytes(); println!("{}", std::str::from_utf8(&bytes).unwrap());}