1
+ #![ cfg_attr( feature = "with-std-future" , feature( futures_api) ) ]
2
+
1
3
extern crate futures;
2
4
#[ cfg( feature = "with-tokio" ) ]
3
5
extern crate tokio;
4
6
#[ cfg_attr( test, macro_use) ]
5
7
extern crate tokio_trace;
6
8
7
- use futures:: { Future , Poll , Sink , StartSend , Stream } ;
9
+ #[ cfg( feature = "with-std-future" ) ]
10
+ use std:: {
11
+ pin:: Pin ,
12
+ task:: Context ,
13
+ } ;
14
+
15
+ use futures:: { Sink , StartSend , Stream } ;
8
16
use tokio_trace:: { dispatcher, Dispatch , Span } ;
9
17
10
18
pub mod executor;
@@ -14,6 +22,10 @@ pub trait Instrument: Sized {
14
22
fn instrument ( self , span : Span ) -> Instrumented < Self > {
15
23
Instrumented { inner : self , span }
16
24
}
25
+
26
+ fn boxed_instrument ( self , span : Span ) -> Instrumented < Pin < Box < Self > > > {
27
+ Instrumented { inner : Box :: pin ( self ) , span }
28
+ }
17
29
}
18
30
19
31
pub trait WithSubscriber : Sized {
@@ -42,11 +54,23 @@ pub struct WithDispatch<T> {
42
54
43
55
impl < T : Sized > Instrument for T { }
44
56
45
- impl < T : Future > Future for Instrumented < T > {
57
+ #[ cfg( feature = "with-std-future" ) ]
58
+ impl < P : std:: future:: Future > std:: future:: Future for Instrumented < Pin < Box < P > > > {
59
+ type Output = P :: Output ;
60
+
61
+ fn poll ( self : Pin < & mut Self > , lw : & mut Context ) -> std:: task:: Poll < Self :: Output > {
62
+ let this = self . get_mut ( ) ;
63
+ let span = & mut this. span ;
64
+ let inner = this. inner . as_mut ( ) ;
65
+ span. enter ( || P :: poll ( inner, lw) )
66
+ }
67
+ }
68
+
69
+ impl < T : futures:: Future > futures:: Future for Instrumented < T > {
46
70
type Item = T :: Item ;
47
71
type Error = T :: Error ;
48
72
49
- fn poll ( & mut self ) -> Poll < Self :: Item , Self :: Error > {
73
+ fn poll ( & mut self ) -> futures :: Poll < Self :: Item , Self :: Error > {
50
74
let span = & mut self . span ;
51
75
let inner = & mut self . inner ;
52
76
span. enter ( || inner. poll ( ) )
@@ -57,7 +81,7 @@ impl<T: Stream> Stream for Instrumented<T> {
57
81
type Item = T :: Item ;
58
82
type Error = T :: Error ;
59
83
60
- fn poll ( & mut self ) -> Poll < Option < Self :: Item > , Self :: Error > {
84
+ fn poll ( & mut self ) -> futures :: Poll < Option < Self :: Item > , Self :: Error > {
61
85
let span = & mut self . span ;
62
86
let inner = & mut self . inner ;
63
87
span. enter ( || inner. poll ( ) )
@@ -74,7 +98,7 @@ impl<T: Sink> Sink for Instrumented<T> {
74
98
span. enter ( || inner. start_send ( item) )
75
99
}
76
100
77
- fn poll_complete ( & mut self ) -> Poll < ( ) , Self :: SinkError > {
101
+ fn poll_complete ( & mut self ) -> futures :: Poll < ( ) , Self :: SinkError > {
78
102
let span = & mut self . span ;
79
103
let inner = & mut self . inner ;
80
104
span. enter ( || inner. poll_complete ( ) )
@@ -102,11 +126,11 @@ impl<T> Instrumented<T> {
102
126
103
127
impl < T : Sized > WithSubscriber for T { }
104
128
105
- impl < T : Future > Future for WithDispatch < T > {
129
+ impl < T : futures :: Future > futures :: Future for WithDispatch < T > {
106
130
type Item = T :: Item ;
107
131
type Error = T :: Error ;
108
132
109
- fn poll ( & mut self ) -> Poll < Self :: Item , Self :: Error > {
133
+ fn poll ( & mut self ) -> futures :: Poll < Self :: Item , Self :: Error > {
110
134
let inner = & mut self . inner ;
111
135
dispatcher:: with_default ( & self . dispatch , || inner. poll ( ) )
112
136
}
@@ -139,7 +163,7 @@ mod tests {
139
163
extern crate tokio;
140
164
141
165
use super :: { test_support:: * , * } ;
142
- use futures:: { future, stream, task, Async } ;
166
+ use futures:: { Async , Future , future, stream, task} ;
143
167
use tokio_trace:: { subscriber:: with_default, Level } ;
144
168
145
169
struct PollN < T , E > {
@@ -148,10 +172,10 @@ mod tests {
148
172
polls : usize ,
149
173
}
150
174
151
- impl < T , E > Future for PollN < T , E > {
175
+ impl < T , E > futures :: Future for PollN < T , E > {
152
176
type Item = T ;
153
177
type Error = E ;
154
- fn poll ( & mut self ) -> Poll < Self :: Item , Self :: Error > {
178
+ fn poll ( & mut self ) -> futures :: Poll < Self :: Item , Self :: Error > {
155
179
self . polls += 1 ;
156
180
if self . polls == self . finish_at {
157
181
self . and_return
0 commit comments