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