simple_hyper_client/util.rs
1/* Copyright (c) Fortanix, Inc.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7use http_body_util::BodyExt;
8use hyper::body::{Body, Buf, Bytes};
9
10/// Collects all of the data frames from this body into a [`Buf`].
11///
12/// As opposed to [`to_bytes()`], this function avoids copying the data
13/// and is useful when you don't need a contiguous slice of data.
14pub async fn aggregate<T>(body: T) -> Result<impl Buf, T::Error>
15where
16 T: Body,
17{
18 Ok(body.collect().await?.aggregate())
19}
20
21/// Collects all of the data frames from this body into [`Bytes`].
22pub async fn to_bytes<T>(body: T) -> Result<Bytes, T::Error>
23where
24 T: Body,
25{
26 Ok(body.collect().await?.to_bytes())
27}