@@ -2,12 +2,12 @@ use crate::enter;
22use futures_core:: future:: Future ;
33use futures_core:: stream:: Stream ;
44use futures_core:: task:: { Context , Poll } ;
5- use futures_task:: { FutureObj , LocalFutureObj , Spawn , LocalSpawn , SpawnError } ;
65use futures_task:: { waker_ref, ArcWake } ;
6+ use futures_task:: { FutureObj , LocalFutureObj , LocalSpawn , Spawn , SpawnError } ;
7+ use futures_util:: pin_mut;
78use futures_util:: stream:: FuturesUnordered ;
89use futures_util:: stream:: StreamExt ;
9- use futures_util:: pin_mut;
10- use std:: cell:: { RefCell } ;
10+ use std:: cell:: RefCell ;
1111use std:: ops:: { Deref , DerefMut } ;
1212use std:: rc:: { Rc , Weak } ;
1313use std:: sync:: Arc ;
@@ -40,7 +40,7 @@ pub struct LocalSpawner {
4040type Incoming = RefCell < Vec < LocalFutureObj < ' static , ( ) > > > ;
4141
4242pub ( crate ) struct ThreadNotify {
43- thread : Thread
43+ thread : Thread ,
4444}
4545
4646thread_local ! {
@@ -58,9 +58,10 @@ impl ArcWake for ThreadNotify {
5858// Set up and run a basic single-threaded spawner loop, invoking `f` on each
5959// turn.
6060fn 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+ ) ;
6465
6566 CURRENT_THREAD_NOTIFY . with ( |thread_notify| {
6667 let waker = waker_ref ( thread_notify) ;
@@ -75,9 +76,10 @@ fn run_executor<T, F: FnMut(&mut Context<'_>) -> Poll<T>>(mut f: F) -> T {
7576}
7677
7778fn 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+ ) ;
8183
8284 CURRENT_THREAD_NOTIFY . with ( |thread_notify| {
8385 let waker = waker_ref ( thread_notify) ;
@@ -98,7 +100,7 @@ impl LocalPool {
98100 /// Get a clonable handle to the pool as a [`Spawn`].
99101 pub fn spawner ( & self ) -> LocalSpawner {
100102 LocalSpawner {
101- incoming : Rc :: downgrade ( & self . incoming )
103+ incoming : Rc :: downgrade ( & self . incoming ) ,
102104 }
103105 }
104106
@@ -164,7 +166,7 @@ impl LocalPool {
164166 /// use futures::future::{ready, pending};
165167 ///
166168 /// let mut pool = LocalPool::new();
167- /// let mut spawner = pool.spawner();
169+ /// let spawner = pool.spawner();
168170 ///
169171 /// spawner.spawn_local(ready(())).unwrap();
170172 /// spawner.spawn_local(ready(())).unwrap();
@@ -212,7 +214,7 @@ impl LocalPool {
212214 /// use futures::future::{ready, pending};
213215 ///
214216 /// let mut pool = LocalPool::new();
215- /// let mut spawner = pool.spawner();
217+ /// let spawner = pool.spawner();
216218 ///
217219 /// spawner.spawn_local(ready(())).unwrap();
218220 /// spawner.spawn_local(ready(())).unwrap();
@@ -229,7 +231,7 @@ impl LocalPool {
229231 /// of the pool's run or poll methods. While the function is running, all tasks
230232 /// in the pool will try to make progress.
231233 pub fn run_until_stalled ( & mut self ) {
232- poll_executor ( |ctx| {
234+ poll_executor ( |ctx| {
233235 let _ = self . poll_pool ( ctx) ;
234236 } ) ;
235237 }
@@ -297,7 +299,9 @@ pub fn block_on_stream<S: Stream + Unpin>(stream: S) -> BlockingStream<S> {
297299
298300/// An iterator which blocks on values from a stream until they become available.
299301#[ derive( Debug ) ]
300- pub struct BlockingStream < S : Stream + Unpin > { stream : S }
302+ pub struct BlockingStream < S : Stream + Unpin > {
303+ stream : S ,
304+ }
301305
302306impl < S : Stream + Unpin > Deref for BlockingStream < S > {
303307 type Target = S ;
@@ -332,10 +336,7 @@ impl<S: Stream + Unpin> Iterator for BlockingStream<S> {
332336}
333337
334338impl 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 > {
339340 if let Some ( incoming) = self . incoming . upgrade ( ) {
340341 incoming. borrow_mut ( ) . push ( future. into ( ) ) ;
341342 Ok ( ( ) )
@@ -354,10 +355,7 @@ impl Spawn for LocalSpawner {
354355}
355356
356357impl 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 > {
361359 if let Some ( incoming) = self . incoming . upgrade ( ) {
362360 incoming. borrow_mut ( ) . push ( future) ;
363361 Ok ( ( ) )
0 commit comments