channels_io/impls/
futures.rs

1use super::prelude::*;
2
3/// Wrapper IO type for [`futures::AsyncRead`] and [`futures::AsyncWrite`].
4///
5/// [`futures::AsyncRead`]: ::futures::AsyncRead
6/// [`futures::AsyncWrite`]:  ::futures::AsyncWrite
7#[derive(Debug)]
8#[pin_project]
9pub struct Futures<T>(#[pin] pub T);
10
11impl_newtype! { Futures }
12
13impl_newtype_read! { Futures: ::futures::io::AsyncRead }
14
15impl<T> AsyncRead for Futures<T>
16where
17	T: ::futures::io::AsyncRead,
18{
19	type Error = ::futures::io::Error;
20
21	fn poll_read_slice(
22		self: Pin<&mut Self>,
23		cx: &mut Context,
24		buf: &mut [u8],
25	) -> Poll<Result<usize, Self::Error>> {
26		let this = self.project();
27		this.0.poll_read(cx, buf)
28	}
29}
30
31impl_newtype_write! { Futures: ::futures::io::AsyncWrite }
32
33impl<T> AsyncWrite for Futures<T>
34where
35	T: ::futures::io::AsyncWrite,
36{
37	type Error = ::futures::io::Error;
38
39	fn poll_write_slice(
40		self: Pin<&mut Self>,
41		cx: &mut Context,
42		buf: &[u8],
43	) -> Poll<Result<usize, Self::Error>> {
44		let this = self.project();
45		this.0.poll_write(cx, buf)
46	}
47
48	fn poll_flush_once(
49		self: Pin<&mut Self>,
50		cx: &mut Context,
51	) -> Poll<Result<(), Self::Error>> {
52		let this = self.project();
53		this.0.poll_flush(cx)
54	}
55}