futures_util_either/
impl_tokio_io.rs1use core::{
2 pin::Pin,
3 task::{Context, Poll},
4};
5use std::io::{Result, SeekFrom};
6
7use tokio::io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite, ReadBuf};
8
9use super::Either;
10
11impl<A, B> AsyncRead for Either<A, B>
13where
14 A: AsyncRead,
15 B: AsyncRead,
16{
17 fn poll_read(
18 self: Pin<&mut Self>,
19 cx: &mut Context<'_>,
20 buf: &mut ReadBuf<'_>,
21 ) -> Poll<Result<()>> {
22 match self.project() {
23 Either::Left(x) => x.poll_read(cx, buf),
24 Either::Right(x) => x.poll_read(cx, buf),
25 }
26 }
27}
28
29impl<A, B> AsyncWrite for Either<A, B>
31where
32 A: AsyncWrite,
33 B: AsyncWrite,
34{
35 fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>> {
36 match self.project() {
37 Either::Left(x) => x.poll_write(cx, buf),
38 Either::Right(x) => x.poll_write(cx, buf),
39 }
40 }
41
42 fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
43 match self.project() {
44 Either::Left(x) => x.poll_flush(cx),
45 Either::Right(x) => x.poll_flush(cx),
46 }
47 }
48
49 fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
50 match self.project() {
51 Either::Left(x) => x.poll_shutdown(cx),
52 Either::Right(x) => x.poll_shutdown(cx),
53 }
54 }
55}
56
57impl<A, B> AsyncSeek for Either<A, B>
59where
60 A: AsyncSeek,
61 B: AsyncSeek,
62{
63 fn start_seek(self: Pin<&mut Self>, position: SeekFrom) -> Result<()> {
64 match self.project() {
65 Either::Left(x) => x.start_seek(position),
66 Either::Right(x) => x.start_seek(position),
67 }
68 }
69
70 fn poll_complete(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<u64>> {
71 match self.project() {
72 Either::Left(x) => x.poll_complete(cx),
73 Either::Right(x) => x.poll_complete(cx),
74 }
75 }
76}
77
78impl<A, B> AsyncBufRead for Either<A, B>
80where
81 A: AsyncBufRead,
82 B: AsyncBufRead,
83{
84 fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<&[u8]>> {
85 match self.project() {
86 Either::Left(x) => x.poll_fill_buf(cx),
87 Either::Right(x) => x.poll_fill_buf(cx),
88 }
89 }
90
91 fn consume(self: Pin<&mut Self>, amt: usize) {
92 match self.project() {
93 Either::Left(x) => x.consume(amt),
94 Either::Right(x) => x.consume(amt),
95 }
96 }
97}