@@ -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,22 @@ 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 > std:: future:: Future for Instrumented < Pin < Box < 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
+ let inner = this. inner . as_mut ( ) ;
79
+ P :: poll ( inner, lw)
80
+ }
81
+ }
82
+
83
+ impl < T : futures:: Future > futures:: Future for Instrumented < T > {
64
84
type Item = T :: Item ;
65
85
type Error = T :: Error ;
66
86
67
- fn poll ( & mut self ) -> Poll < Self :: Item , Self :: Error > {
87
+ fn poll ( & mut self ) -> futures :: Poll < Self :: Item , Self :: Error > {
68
88
let _enter = self . span . enter ( ) ;
69
89
self . inner . poll ( )
70
90
}
@@ -74,7 +94,7 @@ impl<T: Stream> Stream for Instrumented<T> {
74
94
type Item = T :: Item ;
75
95
type Error = T :: Error ;
76
96
77
- fn poll ( & mut self ) -> Poll < Option < Self :: Item > , Self :: Error > {
97
+ fn poll ( & mut self ) -> futures :: Poll < Option < Self :: Item > , Self :: Error > {
78
98
let _enter = self . span . enter ( ) ;
79
99
self . inner . poll ( )
80
100
}
@@ -89,7 +109,7 @@ impl<T: Sink> Sink for Instrumented<T> {
89
109
self . inner . start_send ( item)
90
110
}
91
111
92
- fn poll_complete ( & mut self ) -> Poll < ( ) , Self :: SinkError > {
112
+ fn poll_complete ( & mut self ) -> futures :: Poll < ( ) , Self :: SinkError > {
93
113
let _enter = self . span . enter ( ) ;
94
114
self . inner . poll_complete ( )
95
115
}
@@ -116,11 +136,11 @@ impl<T> Instrumented<T> {
116
136
117
137
impl < T : Sized > WithSubscriber for T { }
118
138
119
- impl < T : Future > Future for WithDispatch < T > {
139
+ impl < T : futures :: Future > futures :: Future for WithDispatch < T > {
120
140
type Item = T :: Item ;
121
141
type Error = T :: Error ;
122
142
123
- fn poll ( & mut self ) -> Poll < Self :: Item , Self :: Error > {
143
+ fn poll ( & mut self ) -> futures :: Poll < Self :: Item , Self :: Error > {
124
144
let inner = & mut self . inner ;
125
145
dispatcher:: with_default ( & self . dispatch , || inner. poll ( ) )
126
146
}
@@ -157,7 +177,7 @@ mod tests {
157
177
extern crate tokio;
158
178
159
179
use super :: { test_support:: * , * } ;
160
- use futures:: { future, stream, task, Async } ;
180
+ use futures:: { future, stream, task, Async , Future } ;
161
181
use tracing:: { subscriber:: with_default, Level } ;
162
182
163
183
struct PollN < T , E > {
@@ -166,10 +186,10 @@ mod tests {
166
186
polls : usize ,
167
187
}
168
188
169
- impl < T , E > Future for PollN < T , E > {
189
+ impl < T , E > futures :: Future for PollN < T , E > {
170
190
type Item = T ;
171
191
type Error = E ;
172
- fn poll ( & mut self ) -> Poll < Self :: Item , Self :: Error > {
192
+ fn poll ( & mut self ) -> futures :: Poll < Self :: Item , Self :: Error > {
173
193
self . polls += 1 ;
174
194
if self . polls == self . finish_at {
175
195
self . and_return
0 commit comments