chiark / gitweb /
read_limited_bytes: take an `initial` argument
[hippotat.git] / src / utils.rs
index 5c1075205bb2eef874e52ade33c3fcf4f9aaf661..4b345d0c4cf8cbd8993a5fd4ce778477be5d0662 100644 (file)
@@ -39,12 +39,13 @@ impl<T> Result<T,ReadLimitedError> {
 }
 
 #[throws(ReadLimitedError)]
-pub async fn read_limited_bytes<S>(limit: usize, stream: &mut S) -> Box<[u8]>
+pub async fn read_limited_bytes<S>(limit: usize, initial: Box<[u8]>,
+                                   stream: &mut S) -> Box<[u8]>
 where S: futures::Stream<Item=Result<hyper::body::Bytes,hyper::Error>>
          + Debug + Unpin,
       // we also require that the Stream is cancellation-safe
 {
-  let mut accum = vec![];
+  let mut accum = initial.into_vec();
   while let Some(item) = stream.next().await {
     let b = item?;
     accum.extend(b);