@@ -210,10 +210,10 @@ impl fmt::Debug for Task {
210
210
/// can be blocked indefinitely until a notification arrives. This can be used
211
211
/// with either futures or streams, with different methods being available on
212
212
/// `Spawn` depending which is used.
213
- pub struct Spawn < T > {
213
+ pub struct Spawn < T : ? Sized > {
214
214
id : usize ,
215
- obj : T ,
216
215
data : LocalMap ,
216
+ obj : T ,
217
217
}
218
218
219
219
/// Spawns a new future, returning the fused future and task.
@@ -233,7 +233,7 @@ pub fn spawn<T>(obj: T) -> Spawn<T> {
233
233
}
234
234
}
235
235
236
- impl < T > Spawn < T > {
236
+ impl < T : ? Sized > Spawn < T > {
237
237
/// Get a shared reference to the object the Spawn is wrapping.
238
238
pub fn get_ref ( & self ) -> & T {
239
239
& self . obj
@@ -245,12 +245,10 @@ impl<T> Spawn<T> {
245
245
}
246
246
247
247
/// Consume the Spawn, returning its inner object
248
- pub fn into_inner ( self ) -> T {
248
+ pub fn into_inner ( self ) -> T where T : Sized {
249
249
self . obj
250
250
}
251
- }
252
251
253
- impl < F : Future > Spawn < F > {
254
252
/// Polls the internal future, scheduling notifications to be sent to the
255
253
/// `notify` argument.
256
254
///
@@ -277,44 +275,43 @@ impl<F: Future> Spawn<F> {
277
275
/// the `id` specified very carefully, explicitly calling functions like the
278
276
/// `notify` argument's `clone_id` and `drop_id` functions. It should be
279
277
/// safe to encode a pointer itself into the `id` specified, such as an
280
- /// `Arc<T >` or a `Box<T >`. The `clone_id` and `drop_id` functions are then
278
+ /// `Arc<N >` or a `Box<N >`. The `clone_id` and `drop_id` functions are then
281
279
/// intended to be sufficient for the memory management related to that
282
280
/// pointer.
283
- pub fn poll_future_notify < T > ( & mut self ,
284
- notify : & T ,
285
- id : usize ) -> Poll < F :: Item , F :: Error >
286
- where T : Clone + Into < NotifyHandle > ,
281
+ pub fn poll_future_notify < N > ( & mut self ,
282
+ notify : & N ,
283
+ id : usize ) -> Poll < T :: Item , T :: Error >
284
+ where N : Clone + Into < NotifyHandle > ,
285
+ T : Future ,
287
286
{
288
287
let mk = || notify. clone ( ) . into ( ) ;
289
288
self . enter ( BorrowedUnpark :: new ( & mk, id) , |f| f. poll ( ) )
290
289
}
291
- }
292
290
293
- impl < S : Stream > Spawn < S > {
294
291
/// Like `poll_future_notify`, except polls the underlying stream.
295
- pub fn poll_stream_notify < T > ( & mut self ,
296
- notify : & T ,
292
+ pub fn poll_stream_notify < N > ( & mut self ,
293
+ notify : & N ,
297
294
id : usize )
298
- -> Poll < Option < S :: Item > , S :: Error >
299
- where T : Clone + Into < NotifyHandle > ,
295
+ -> Poll < Option < T :: Item > , T :: Error >
296
+ where N : Clone + Into < NotifyHandle > ,
297
+ T : Stream ,
300
298
{
301
299
let mk = || notify. clone ( ) . into ( ) ;
302
300
self . enter ( BorrowedUnpark :: new ( & mk, id) , |s| s. poll ( ) )
303
301
}
304
- }
305
302
306
- impl < S : Sink > Spawn < S > {
307
303
/// Invokes the underlying `start_send` method with this task in place.
308
304
///
309
305
/// If the underlying operation returns `NotReady` then the `notify` value
310
306
/// passed in will receive a notification when the operation is ready to be
311
307
/// attempted again.
312
- pub fn start_send_notify < T > ( & mut self ,
313
- value : S :: SinkItem ,
314
- notify : & T ,
308
+ pub fn start_send_notify < N > ( & mut self ,
309
+ value : T :: SinkItem ,
310
+ notify : & N ,
315
311
id : usize )
316
- -> StartSend < S :: SinkItem , S :: SinkError >
317
- where T : Clone + Into < NotifyHandle > ,
312
+ -> StartSend < T :: SinkItem , T :: SinkError >
313
+ where N : Clone + Into < NotifyHandle > ,
314
+ T : Sink ,
318
315
{
319
316
let mk = || notify. clone ( ) . into ( ) ;
320
317
self . enter ( BorrowedUnpark :: new ( & mk, id) , |s| s. start_send ( value) )
@@ -325,11 +322,12 @@ impl<S: Sink> Spawn<S> {
325
322
/// If the underlying operation returns `NotReady` then the `notify` value
326
323
/// passed in will receive a notification when the operation is ready to be
327
324
/// attempted again.
328
- pub fn poll_flush_notify < T > ( & mut self ,
329
- notify : & T ,
325
+ pub fn poll_flush_notify < N > ( & mut self ,
326
+ notify : & N ,
330
327
id : usize )
331
- -> Poll < ( ) , S :: SinkError >
332
- where T : Clone + Into < NotifyHandle > ,
328
+ -> Poll < ( ) , T :: SinkError >
329
+ where N : Clone + Into < NotifyHandle > ,
330
+ T : Sink ,
333
331
{
334
332
let mk = || notify. clone ( ) . into ( ) ;
335
333
self . enter ( BorrowedUnpark :: new ( & mk, id) , |s| s. poll_complete ( ) )
@@ -340,18 +338,17 @@ impl<S: Sink> Spawn<S> {
340
338
/// If the underlying operation returns `NotReady` then the `notify` value
341
339
/// passed in will receive a notification when the operation is ready to be
342
340
/// attempted again.
343
- pub fn close_notify < T > ( & mut self ,
344
- notify : & T ,
341
+ pub fn close_notify < N > ( & mut self ,
342
+ notify : & N ,
345
343
id : usize )
346
- -> Poll < ( ) , S :: SinkError >
347
- where T : Clone + Into < NotifyHandle > ,
344
+ -> Poll < ( ) , T :: SinkError >
345
+ where N : Clone + Into < NotifyHandle > ,
346
+ T : Sink ,
348
347
{
349
348
let mk = || notify. clone ( ) . into ( ) ;
350
349
self . enter ( BorrowedUnpark :: new ( & mk, id) , |s| s. close ( ) )
351
350
}
352
- }
353
351
354
- impl < T > Spawn < T > {
355
352
fn enter < F , R > ( & mut self , unpark : BorrowedUnpark , f : F ) -> R
356
353
where F : FnOnce ( & mut T ) -> R
357
354
{
@@ -366,10 +363,10 @@ impl<T> Spawn<T> {
366
363
}
367
364
}
368
365
369
- impl < T : fmt:: Debug > fmt:: Debug for Spawn < T > {
366
+ impl < T : fmt:: Debug + ? Sized > fmt:: Debug for Spawn < T > {
370
367
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
371
368
f. debug_struct ( "Spawn" )
372
- . field ( "obj" , & self . obj )
369
+ . field ( "obj" , & & self . obj )
373
370
. finish ( )
374
371
}
375
372
}
0 commit comments