14
14
//!
15
15
//! [`Instrument`]: trait.Instrument.html
16
16
//! [`WithSubscriber`]: trait.WithSubscriber.html
17
+ #![ cfg_attr( feature = "with-std-future" , feature( futures_api) ) ]
17
18
extern crate futures;
18
19
#[ cfg( feature = "tokio" ) ]
19
20
extern crate tokio;
@@ -22,7 +23,13 @@ extern crate tokio_executor;
22
23
#[ cfg_attr( test, macro_use) ]
23
24
extern crate tokio_trace;
24
25
25
- use futures:: { Future , Poll , Sink , StartSend , Stream } ;
26
+ #[ cfg( feature = "with-std-future" ) ]
27
+ use std:: {
28
+ pin:: Pin ,
29
+ task:: Context ,
30
+ } ;
31
+
32
+ use futures:: { Sink , StartSend , Stream } ;
26
33
use tokio_trace:: { dispatcher, Dispatch , Span } ;
27
34
28
35
pub mod executor;
@@ -32,6 +39,10 @@ pub trait Instrument: Sized {
32
39
fn instrument ( self , span : Span ) -> Instrumented < Self > {
33
40
Instrumented { inner : self , span }
34
41
}
42
+
43
+ fn boxed_instrument ( self , span : Span ) -> Instrumented < Pin < Box < Self > > > {
44
+ Instrumented { inner : Box :: pin ( self ) , span }
45
+ }
35
46
}
36
47
37
48
pub trait WithSubscriber : Sized {
@@ -60,11 +71,23 @@ pub struct WithDispatch<T> {
60
71
61
72
impl < T : Sized > Instrument for T { }
62
73
63
- impl < T : Future > Future for Instrumented < T > {
74
+ #[ cfg( feature = "with-std-future" ) ]
75
+ impl < P : std:: future:: Future > std:: future:: Future for Instrumented < Pin < Box < P > > > {
76
+ type Output = P :: Output ;
77
+
78
+ fn poll ( self : Pin < & mut Self > , lw : & mut Context ) -> std:: task:: Poll < Self :: Output > {
79
+ let this = self . get_mut ( ) ;
80
+ let span = & mut this. span ;
81
+ let inner = this. inner . as_mut ( ) ;
82
+ span. enter ( || P :: poll ( inner, lw) )
83
+ }
84
+ }
85
+
86
+ impl < T : futures:: Future > futures:: Future for Instrumented < T > {
64
87
type Item = T :: Item ;
65
88
type Error = T :: Error ;
66
89
67
- fn poll ( & mut self ) -> Poll < Self :: Item , Self :: Error > {
90
+ fn poll ( & mut self ) -> futures :: Poll < Self :: Item , Self :: Error > {
68
91
let span = & mut self . span ;
69
92
let inner = & mut self . inner ;
70
93
span. enter ( || inner. poll ( ) )
@@ -75,7 +98,7 @@ impl<T: Stream> Stream for Instrumented<T> {
75
98
type Item = T :: Item ;
76
99
type Error = T :: Error ;
77
100
78
- fn poll ( & mut self ) -> Poll < Option < Self :: Item > , Self :: Error > {
101
+ fn poll ( & mut self ) -> futures :: Poll < Option < Self :: Item > , Self :: Error > {
79
102
let span = & mut self . span ;
80
103
let inner = & mut self . inner ;
81
104
span. enter ( || inner. poll ( ) )
@@ -92,7 +115,7 @@ impl<T: Sink> Sink for Instrumented<T> {
92
115
span. enter ( || inner. start_send ( item) )
93
116
}
94
117
95
- fn poll_complete ( & mut self ) -> Poll < ( ) , Self :: SinkError > {
118
+ fn poll_complete ( & mut self ) -> futures :: Poll < ( ) , Self :: SinkError > {
96
119
let span = & mut self . span ;
97
120
let inner = & mut self . inner ;
98
121
span. enter ( || inner. poll_complete ( ) )
@@ -120,11 +143,11 @@ impl<T> Instrumented<T> {
120
143
121
144
impl < T : Sized > WithSubscriber for T { }
122
145
123
- impl < T : Future > Future for WithDispatch < T > {
146
+ impl < T : futures :: Future > futures :: Future for WithDispatch < T > {
124
147
type Item = T :: Item ;
125
148
type Error = T :: Error ;
126
149
127
- fn poll ( & mut self ) -> Poll < Self :: Item , Self :: Error > {
150
+ fn poll ( & mut self ) -> futures :: Poll < Self :: Item , Self :: Error > {
128
151
let inner = & mut self . inner ;
129
152
dispatcher:: with_default ( & self . dispatch , || inner. poll ( ) )
130
153
}
@@ -157,7 +180,7 @@ mod tests {
157
180
extern crate tokio;
158
181
159
182
use super :: { test_support:: * , * } ;
160
- use futures:: { future, stream, task, Async } ;
183
+ use futures:: { Async , Future , future, stream, task} ;
161
184
use tokio_trace:: { subscriber:: with_default, Level } ;
162
185
163
186
struct PollN < T , E > {
@@ -166,10 +189,10 @@ mod tests {
166
189
polls : usize ,
167
190
}
168
191
169
- impl < T , E > Future for PollN < T , E > {
192
+ impl < T , E > futures :: Future for PollN < T , E > {
170
193
type Item = T ;
171
194
type Error = E ;
172
- fn poll ( & mut self ) -> Poll < Self :: Item , Self :: Error > {
195
+ fn poll ( & mut self ) -> futures :: Poll < Self :: Item , Self :: Error > {
173
196
self . polls += 1 ;
174
197
if self . polls == self . finish_at {
175
198
self . and_return
0 commit comments