@@ -2,12 +2,12 @@ use crate::enter;
2
2
use futures_core:: future:: Future ;
3
3
use futures_core:: stream:: Stream ;
4
4
use futures_core:: task:: { Context , Poll } ;
5
- use futures_task:: { FutureObj , LocalFutureObj , Spawn , LocalSpawn , SpawnError } ;
6
5
use futures_task:: { waker_ref, ArcWake } ;
6
+ use futures_task:: { FutureObj , LocalFutureObj , LocalSpawn , Spawn , SpawnError } ;
7
+ use futures_util:: pin_mut;
7
8
use futures_util:: stream:: FuturesUnordered ;
8
9
use futures_util:: stream:: StreamExt ;
9
- use futures_util:: pin_mut;
10
- use std:: cell:: { RefCell } ;
10
+ use std:: cell:: RefCell ;
11
11
use std:: ops:: { Deref , DerefMut } ;
12
12
use std:: rc:: { Rc , Weak } ;
13
13
use std:: sync:: Arc ;
@@ -40,7 +40,7 @@ pub struct LocalSpawner {
40
40
type Incoming = RefCell < Vec < LocalFutureObj < ' static , ( ) > > > ;
41
41
42
42
pub ( crate ) struct ThreadNotify {
43
- thread : Thread
43
+ thread : Thread ,
44
44
}
45
45
46
46
thread_local ! {
@@ -58,9 +58,10 @@ impl ArcWake for ThreadNotify {
58
58
// Set up and run a basic single-threaded spawner loop, invoking `f` on each
59
59
// turn.
60
60
fn run_executor < T , F : FnMut ( & mut Context < ' _ > ) -> Poll < T > > ( mut f : F ) -> T {
61
- let _enter = enter ( )
62
- . expect ( "cannot execute `LocalPool` executor from within \
63
- another executor") ;
61
+ let _enter = enter ( ) . expect (
62
+ "cannot execute `LocalPool` executor from within \
63
+ another executor",
64
+ ) ;
64
65
65
66
CURRENT_THREAD_NOTIFY . with ( |thread_notify| {
66
67
let waker = waker_ref ( thread_notify) ;
@@ -75,9 +76,10 @@ fn run_executor<T, F: FnMut(&mut Context<'_>) -> Poll<T>>(mut f: F) -> T {
75
76
}
76
77
77
78
fn poll_executor < T , F : FnMut ( & mut Context < ' _ > ) -> T > ( mut f : F ) -> T {
78
- let _enter = enter ( )
79
- . expect ( "cannot execute `LocalPool` executor from within \
80
- another executor") ;
79
+ let _enter = enter ( ) . expect (
80
+ "cannot execute `LocalPool` executor from within \
81
+ another executor",
82
+ ) ;
81
83
82
84
CURRENT_THREAD_NOTIFY . with ( |thread_notify| {
83
85
let waker = waker_ref ( thread_notify) ;
@@ -98,7 +100,7 @@ impl LocalPool {
98
100
/// Get a clonable handle to the pool as a [`Spawn`].
99
101
pub fn spawner ( & self ) -> LocalSpawner {
100
102
LocalSpawner {
101
- incoming : Rc :: downgrade ( & self . incoming )
103
+ incoming : Rc :: downgrade ( & self . incoming ) ,
102
104
}
103
105
}
104
106
@@ -164,7 +166,7 @@ impl LocalPool {
164
166
/// use futures::future::{ready, pending};
165
167
///
166
168
/// let mut pool = LocalPool::new();
167
- /// let mut spawner = pool.spawner();
169
+ /// let spawner = pool.spawner();
168
170
///
169
171
/// spawner.spawn_local(ready(())).unwrap();
170
172
/// spawner.spawn_local(ready(())).unwrap();
@@ -212,7 +214,7 @@ impl LocalPool {
212
214
/// use futures::future::{ready, pending};
213
215
///
214
216
/// let mut pool = LocalPool::new();
215
- /// let mut spawner = pool.spawner();
217
+ /// let spawner = pool.spawner();
216
218
///
217
219
/// spawner.spawn_local(ready(())).unwrap();
218
220
/// spawner.spawn_local(ready(())).unwrap();
@@ -229,7 +231,7 @@ impl LocalPool {
229
231
/// of the pool's run or poll methods. While the function is running, all tasks
230
232
/// in the pool will try to make progress.
231
233
pub fn run_until_stalled ( & mut self ) {
232
- poll_executor ( |ctx| {
234
+ poll_executor ( |ctx| {
233
235
let _ = self . poll_pool ( ctx) ;
234
236
} ) ;
235
237
}
@@ -297,7 +299,9 @@ pub fn block_on_stream<S: Stream + Unpin>(stream: S) -> BlockingStream<S> {
297
299
298
300
/// An iterator which blocks on values from a stream until they become available.
299
301
#[ derive( Debug ) ]
300
- pub struct BlockingStream < S : Stream + Unpin > { stream : S }
302
+ pub struct BlockingStream < S : Stream + Unpin > {
303
+ stream : S ,
304
+ }
301
305
302
306
impl < S : Stream + Unpin > Deref for BlockingStream < S > {
303
307
type Target = S ;
@@ -332,10 +336,7 @@ impl<S: Stream + Unpin> Iterator for BlockingStream<S> {
332
336
}
333
337
334
338
impl Spawn for LocalSpawner {
335
- fn spawn_obj (
336
- & self ,
337
- future : FutureObj < ' static , ( ) > ,
338
- ) -> Result < ( ) , SpawnError > {
339
+ fn spawn_obj ( & self , future : FutureObj < ' static , ( ) > ) -> Result < ( ) , SpawnError > {
339
340
if let Some ( incoming) = self . incoming . upgrade ( ) {
340
341
incoming. borrow_mut ( ) . push ( future. into ( ) ) ;
341
342
Ok ( ( ) )
@@ -354,10 +355,7 @@ impl Spawn for LocalSpawner {
354
355
}
355
356
356
357
impl LocalSpawn for LocalSpawner {
357
- fn spawn_local_obj (
358
- & self ,
359
- future : LocalFutureObj < ' static , ( ) > ,
360
- ) -> Result < ( ) , SpawnError > {
358
+ fn spawn_local_obj ( & self , future : LocalFutureObj < ' static , ( ) > ) -> Result < ( ) , SpawnError > {
361
359
if let Some ( incoming) = self . incoming . upgrade ( ) {
362
360
incoming. borrow_mut ( ) . push ( future) ;
363
361
Ok ( ( ) )
0 commit comments