@@ -22,7 +22,12 @@ extern crate tokio_executor;
22
22
#[ cfg_attr( test, macro_use) ]
23
23
extern crate tracing;
24
24
25
- use futures:: { Future , Poll , Sink , StartSend , Stream } ;
25
+ use std:: {
26
+ pin:: Pin ,
27
+ task:: Context ,
28
+ } ;
29
+
30
+ use futures:: { Sink , StartSend , Stream } ;
26
31
use tracing:: { dispatcher, Dispatch , Span } ;
27
32
28
33
pub mod executor;
@@ -32,6 +37,10 @@ pub trait Instrument: Sized {
32
37
fn instrument ( self , span : Span ) -> Instrumented < Self > {
33
38
Instrumented { inner : self , span }
34
39
}
40
+
41
+ fn boxed_instrument ( self , span : Span ) -> Instrumented < Pin < Box < Self > > > {
42
+ Instrumented { inner : Box :: pin ( self ) , span }
43
+ }
35
44
}
36
45
37
46
pub trait WithSubscriber : Sized {
@@ -60,11 +69,21 @@ pub struct WithDispatch<T> {
60
69
61
70
impl < T : Sized > Instrument for T { }
62
71
63
- impl < T : Future > Future for Instrumented < T > {
72
+ impl < P : std:: future:: Future + Unpin > std:: future:: Future for Instrumented < P > {
73
+ type Output = P :: Output ;
74
+
75
+ fn poll ( self : Pin < & mut Self > , lw : & mut Context ) -> std:: task:: Poll < Self :: Output > {
76
+ let this = self . get_mut ( ) ;
77
+ let _enter = this. span . enter ( ) ;
78
+ Pin :: new ( & mut this. inner ) . poll ( lw)
79
+ }
80
+ }
81
+
82
+ impl < T : futures:: Future > futures:: Future for Instrumented < T > {
64
83
type Item = T :: Item ;
65
84
type Error = T :: Error ;
66
85
67
- fn poll ( & mut self ) -> Poll < Self :: Item , Self :: Error > {
86
+ fn poll ( & mut self ) -> futures :: Poll < Self :: Item , Self :: Error > {
68
87
let _enter = self . span . enter ( ) ;
69
88
self . inner . poll ( )
70
89
}
@@ -74,7 +93,7 @@ impl<T: Stream> Stream for Instrumented<T> {
74
93
type Item = T :: Item ;
75
94
type Error = T :: Error ;
76
95
77
- fn poll ( & mut self ) -> Poll < Option < Self :: Item > , Self :: Error > {
96
+ fn poll ( & mut self ) -> futures :: Poll < Option < Self :: Item > , Self :: Error > {
78
97
let _enter = self . span . enter ( ) ;
79
98
self . inner . poll ( )
80
99
}
@@ -89,7 +108,7 @@ impl<T: Sink> Sink for Instrumented<T> {
89
108
self . inner . start_send ( item)
90
109
}
91
110
92
- fn poll_complete ( & mut self ) -> Poll < ( ) , Self :: SinkError > {
111
+ fn poll_complete ( & mut self ) -> futures :: Poll < ( ) , Self :: SinkError > {
93
112
let _enter = self . span . enter ( ) ;
94
113
self . inner . poll_complete ( )
95
114
}
@@ -116,11 +135,11 @@ impl<T> Instrumented<T> {
116
135
117
136
impl < T : Sized > WithSubscriber for T { }
118
137
119
- impl < T : Future > Future for WithDispatch < T > {
138
+ impl < T : futures :: Future > futures :: Future for WithDispatch < T > {
120
139
type Item = T :: Item ;
121
140
type Error = T :: Error ;
122
141
123
- fn poll ( & mut self ) -> Poll < Self :: Item , Self :: Error > {
142
+ fn poll ( & mut self ) -> futures :: Poll < Self :: Item , Self :: Error > {
124
143
let inner = & mut self . inner ;
125
144
dispatcher:: with_default ( & self . dispatch , || inner. poll ( ) )
126
145
}
@@ -157,7 +176,7 @@ mod tests {
157
176
extern crate tokio;
158
177
159
178
use super :: { test_support:: * , * } ;
160
- use futures:: { future, stream, task, Async } ;
179
+ use futures:: { future, stream, task, Async , Future } ;
161
180
use tracing:: { subscriber:: with_default, Level } ;
162
181
163
182
struct PollN < T , E > {
@@ -166,10 +185,10 @@ mod tests {
166
185
polls : usize ,
167
186
}
168
187
169
- impl < T , E > Future for PollN < T , E > {
188
+ impl < T , E > futures :: Future for PollN < T , E > {
170
189
type Item = T ;
171
190
type Error = E ;
172
- fn poll ( & mut self ) -> Poll < Self :: Item , Self :: Error > {
191
+ fn poll ( & mut self ) -> futures :: Poll < Self :: Item , Self :: Error > {
173
192
self . polls += 1 ;
174
193
if self . polls == self . finish_at {
175
194
self . and_return
0 commit comments