).await {
Ok(all) => all,
Err(ReadLimitedError::Truncated { sofar,.. }) => sofar,
- Err(ReadLimitedError::Hyper(e)) => throw!(e),
+ Err(ReadLimitedError::Http(e)) => throw!(e),
};
let boundary_finder = memmem::Finder::new(&boundary);
}
#[derive(Error,Debug)]
-pub enum ReadLimitedError {
+pub enum ReadLimitedError<H: std::error::Error + 'static> {
#[error("maximum size {limit} exceeded")]
Truncated { sofar: Box<[u8]>, limit: usize },
#[error("HTTP error {0}")]
- Hyper(#[from] hyper::Error),
+ Http(#[from] H),
}
-impl ReadLimitedError {
+impl ReadLimitedError<hyper::Error> {
pub fn discard_data(&mut self) { match self {
ReadLimitedError::Truncated { sofar,.. } => { mem::take(sofar); },
_ => { },
} }
}
#[ext]
-pub impl<T> Result<T,ReadLimitedError> {
+pub impl<T> Result<T,ReadLimitedError<hyper::Error>> {
fn discard_data(self) -> Self {
self.map_err(|mut e| { e.discard_data(); e })
}
}
}
-#[throws(ReadLimitedError)]
-pub async fn read_limited_bytes<S>(limit: usize, initial: Box<[u8]>,
+#[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,hyper::Error>>
+where S: futures::Stream<Item=Result<hyper::body::Bytes, H>>
+ Debug + Unpin,
+ H: std::error::Error + 'static,
// we also require that the Stream is cancellation-safe
{
let mut accum = initial.into_vec();