We're going to use futures::stream::unfold().
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
let mut resp = resp.into_body();
let max_body = c.ic.max_batch_down.sat() + MAX_OVERHEAD;
let resp = read_limited_bytes(
- max_body, default(), default(), &mut resp
+ max_body, default(), default(), Pin::new(&mut resp),
).await
.discard_data().context("fetching response body")?;
ic.max_batch_up.sat(),
initial,
length_hint,
- &mut body
+ Pin::new(&mut body),
).await.context("read request body")?;
let (meta, mut comps) =
let mut body = req.into_body();
let initial = match read_limited_bytes(
- METADATA_MAX_LEN, default(), length_hint, &mut body
+ METADATA_MAX_LEN, default(), length_hint, Pin::new(&mut body),
).await {
Ok(all) => all,
Err(ReadLimitedError::Truncated { sofar,.. }) => sofar,
#[throws(ReadLimitedError<H>)]
pub async fn read_limited_bytes<S, H>(limit: usize, initial: Box<[u8]>,
capacity: usize,
- stream: &mut S) -> Box<[u8]>
-where S: futures::Stream<Item=Result<hyper::body::Bytes, H>>
- + Debug + Unpin,
+ mut stream: Pin<&mut S>) -> Box<[u8]>
+where S: futures::Stream<Item=Result<hyper::body::Bytes, H>>,
H: std::error::Error + 'static,
// we also require that the Stream is cancellation-safe
{