chiark / gitweb /
ReadLimitedError: Don't demand that the stream is Unpin and Debug
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 1 Feb 2025 11:21:29 +0000 (11:21 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 1 Feb 2025 20:14:58 +0000 (20:14 +0000)
We're going to use futures::stream::unfold().

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
client/client.rs
server/suser.rs
server/sweb.rs
src/utils.rs

index bebb83df1e47f28b81e6f9372dff875a0647de51..5b25ea77043c4320bb5ce9cc67d0becb78149c42 100644 (file)
@@ -163,7 +163,7 @@ fn submit_request<'r, 'c:'r, C:Hcc>(
       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")?;
 
index 68cb4a4e11d249c807b8c3225fd0fd471618da91..aadcaf616d6ed162d675203e87f778934ca14632 100644 (file)
@@ -129,7 +129,7 @@ pub async fn run(global: Arc<Global>,
             ic.max_batch_up.sat(),
             initial,
             length_hint,
-            &mut body
+            Pin::new(&mut body),
           ).await.context("read request body")?;
 
           let (meta, mut comps) =
index 69afc903b0b6e50008919b627773865a663a8908..27c82e0eb69d5480d3c2acf0b93441686734d82d 100644 (file)
@@ -87,7 +87,7 @@ pub async fn handle(
 
     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,
index 5dbb61610ed49ae7008912e0a534d4b5adf2f53b..b15a3080ac3d0c43e8775ef3538e2cf15eaff40c 100644 (file)
@@ -55,9 +55,8 @@ pub impl io::Error {
 #[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
 {