nyquest_interface/async/
body.rs1use std::io;
6use std::pin::Pin;
7use std::task::{Context, Poll};
8
9use futures_io::{AsyncRead, AsyncSeek};
10
11pub trait SizedBodyStream: AsyncRead + AsyncSeek + Send + 'static {}
13
14pub trait UnsizedBodyStream: AsyncRead + Send + 'static {}
16
17pub enum BoxedStream {
19 Sized {
21 stream: Pin<Box<dyn SizedBodyStream>>,
23 content_length: u64,
25 },
26 Unsized {
28 stream: Pin<Box<dyn UnsizedBodyStream>>,
30 },
31}
32
33pub type Body = crate::body::Body<BoxedStream>;
35
36impl<S: AsyncRead + AsyncSeek + Send + 'static + ?Sized> SizedBodyStream for S {}
37impl<S: AsyncRead + Send + 'static + ?Sized> UnsizedBodyStream for S {}
38
39impl AsyncRead for BoxedStream {
40 fn poll_read(
41 self: Pin<&mut Self>,
42 cx: &mut Context<'_>,
43 buf: &mut [u8],
44 ) -> Poll<io::Result<usize>> {
45 match self.get_mut() {
46 BoxedStream::Sized { stream, .. } => Pin::new(stream).poll_read(cx, buf),
47 BoxedStream::Unsized { stream } => Pin::new(stream).poll_read(cx, buf),
48 }
49 }
50}