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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#![crate_type = "proc-macro"]
#![recursion_limit = "256"]
#![doc(html_root_url = "https://docs.rs/futures-enum/0.1.0")]
extern crate proc_macro;
use derive_utils::quick_derive;
use proc_macro::TokenStream;
#[proc_macro_derive(Future)]
pub fn derive_future(input: TokenStream) -> TokenStream {
quick_derive! {
input,
(::core::future::Future),
trait Future {
type Output;
fn poll(
self: ::core::pin::Pin<&mut Self>,
lw: &::core::task::LocalWaker
) -> ::core::task::Poll<Self::Output>;
}
}
}
#[proc_macro_derive(Stream)]
pub fn derive_stream(input: TokenStream) -> TokenStream {
quick_derive! {
input,
(::futures::stream::Stream),
trait Stream {
type Item;
#[inline]
fn poll_next(
self: ::core::pin::Pin<&mut Self>,
lw: &::core::task::LocalWaker,
) -> ::core::task::Poll<::core::option::Option<Self::Item>>;
}
}
}
#[proc_macro_derive(Sink)]
pub fn derive_sink(input: TokenStream) -> TokenStream {
quick_derive! {
input,
(::futures::sink::Sink),
trait Sink {
type SinkItem;
type SinkError;
#[inline]
fn poll_ready(
self: ::core::pin::Pin<&mut Self>,
lw: &::core::task::LocalWaker,
) -> ::core::task::Poll<::core::result::Result<(), Self::SinkError>>;
#[inline]
fn start_send(
self: ::core::pin::Pin<&mut Self>,
item: Self::SinkItem,
) -> ::core::result::Result<(), Self::SinkError>;
#[inline]
fn poll_flush(
self: ::core::pin::Pin<&mut Self>,
lw: &::core::task::LocalWaker,
) -> ::core::task::Poll<::core::result::Result<(), Self::SinkError>>;
#[inline]
fn poll_close(
self: ::core::pin::Pin<&mut Self>,
lw: &::core::task::LocalWaker,
) -> ::core::task::Poll<::core::result::Result<(), Self::SinkError>>;
}
}
}
#[proc_macro_derive(AsyncRead)]
pub fn derive_async_read(input: TokenStream) -> TokenStream {
quick_derive! {
input,
(::futures::io::AsyncRead),
trait AsyncRead {
#[inline]
unsafe fn initializer(&self) -> ::futures::io::Initializer;
#[inline]
fn poll_read(
&mut self,
lw: &::core::task::LocalWaker,
buf: &mut [u8],
) -> ::core::task::Poll<::core::result::Result<usize, ::futures::io::Error>>;
#[inline]
fn poll_vectored_read(
&mut self,
lw: &::core::task::LocalWaker,
vec: &mut [&mut ::futures::io::IoVec],
) -> ::core::task::Poll<::core::result::Result<usize, ::futures::io::Error>>;
}
}
}
#[proc_macro_derive(AsyncWrite)]
pub fn derive_async_write(input: TokenStream) -> TokenStream {
quick_derive! {
input,
(::futures::io::AsyncWrite),
trait AsyncWrite {
#[inline]
fn poll_write(
&mut self,
lw: &::core::task::LocalWaker,
buf: &[u8],
) -> ::core::task::Poll<::core::result::Result<usize, ::futures::io::Error>>;
#[inline]
fn poll_vectored_write(
&mut self,
lw: &::core::task::LocalWaker,
vec: &[&::futures::io::IoVec],
) -> ::core::task::Poll<::core::result::Result<usize, ::futures::io::Error>>;
#[inline]
fn poll_flush(
&mut self,
lw: &::core::task::LocalWaker,
) -> ::core::task::Poll<::core::result::Result<(), ::futures::io::Error>>;
#[inline]
fn poll_close(
&mut self,
lw: &::core::task::LocalWaker,
) -> ::core::task::Poll<::core::result::Result<(), ::futures::io::Error>>;
}
}
}