async_compression/tokio/bufread/generic/
decoder.rs

1use crate::{
2    codecs::DecodeV2,
3    core::util::{PartialBuffer, WriteBuffer},
4    generic::bufread::impl_decoder,
5};
6
7use std::{
8    io::{IoSlice, Result},
9    pin::Pin,
10    task::{Context, Poll},
11};
12use tokio::io::{AsyncBufRead, AsyncRead, AsyncWrite, ReadBuf};
13
14impl_decoder!();
15
16impl<R: AsyncBufRead, D: DecodeV2> AsyncRead for Decoder<R, D> {
17    fn poll_read(
18        self: Pin<&mut Self>,
19        cx: &mut Context<'_>,
20        buf: &mut ReadBuf<'_>,
21    ) -> Poll<Result<()>> {
22        super::poll_read(buf, |output| self.do_poll_read(cx, output))
23    }
24}
25
26impl<R: AsyncWrite, D> AsyncWrite for Decoder<R, D> {
27    fn poll_write(
28        mut self: Pin<&mut Self>,
29        cx: &mut Context<'_>,
30        buf: &[u8],
31    ) -> Poll<Result<usize>> {
32        self.get_pin_mut().poll_write(cx, buf)
33    }
34
35    fn poll_write_vectored(
36        mut self: Pin<&mut Self>,
37        cx: &mut Context<'_>,
38        mut bufs: &[IoSlice<'_>],
39    ) -> Poll<Result<usize>> {
40        self.get_pin_mut().poll_write_vectored(cx, bufs)
41    }
42
43    fn is_write_vectored(&self) -> bool {
44        self.get_ref().is_write_vectored()
45    }
46
47    fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
48        self.get_pin_mut().poll_flush(cx)
49    }
50
51    fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
52        self.get_pin_mut().poll_shutdown(cx)
53    }
54}