1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
macro_rules! decoder {
($(#[$attr:meta])* $name:ident) => {
$(#[$attr])*
#[pin_project::pin_project]
#[derive(Debug)]
pub struct $name<W: futures_io::AsyncWrite> {
#[pin]
inner: crate::write::Decoder<W, crate::codec::$name>,
}
impl<W: futures_io::AsyncWrite> $name<W> {
pub fn new(read: W) -> $name<W> {
$name {
inner: crate::write::Decoder::new(read, crate::codec::$name::new()),
}
}
pub fn get_ref(&self) -> &W {
self.inner.get_ref()
}
pub fn get_mut(&mut self) -> &mut W {
self.inner.get_mut()
}
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut W> {
self.project().inner.get_pin_mut()
}
pub fn into_inner(self) -> W {
self.inner.into_inner()
}
}
impl<W: futures_io::AsyncWrite> futures_io::AsyncWrite for $name<W> {
fn poll_write(
self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
buf: &[u8],
) -> std::task::Poll<std::io::Result<usize>> {
self.project().inner.poll_write(cx, buf)
}
fn poll_flush(
self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<std::io::Result<()>> {
self.project().inner.poll_flush(cx)
}
fn poll_close(
self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<std::io::Result<()>> {
self.project().inner.poll_close(cx)
}
}
const _: () = {
fn _assert() {
use crate::util::{_assert_send, _assert_sync};
use core::pin::Pin;
use futures_io::AsyncWrite;
_assert_send::<$name<Pin<Box<dyn AsyncWrite + Send>>>>();
_assert_sync::<$name<Pin<Box<dyn AsyncWrite + Sync>>>>();
}
};
}
}