fn enter<F, R, P>(scheduler: &mut BasicScheduler<P>, f: F) -> R
where
    F: FnOnce(&mut BasicScheduler<P>, &Context) -> R,
    P: Park,
{
    // Ensures the run queue is placed back in the `BasicScheduler` instance
    // once `block_on` returns.`
    struct Guard<'a, P: Park> {
        context: Option<Context>,
        scheduler: &'a mut BasicScheduler<P>,
    }

    impl<P: Park> Drop for Guard<'_, P> {
        fn drop(&mut self) {
            let Context { tasks, .. } = self.context.take().expect("context missing");
            self.scheduler.tasks = Some(tasks.into_inner());
        }
    }

    // Remove `tasks` from `self` and place it in a `Context`.
    let tasks = scheduler.tasks.take().expect("invalid state");

    let guard = Guard {
        context: Some(Context {
            shared: scheduler.spawner.shared.clone(),
            tasks: RefCell::new(tasks),
        }),
        scheduler,
    };

    let context = guard.context.as_ref().unwrap();
    let scheduler = &mut *guard.scheduler;

    CURRENT.set(context, || f(scheduler, context))
}
/// Enter the scheduler context. This sets the queue and other necessary
/// scheduler state in the thread-local
Enter the scheduler context. This sets the queue and other necessary
scheduler state in the thread-local
Enter the scheduler context . This sets the queue and other necessary scheduler state in the thread - local
fn enter<F, R, P>(scheduler: &mut BasicScheduler<P>, f: F) -> R
where
    F: FnOnce(&mut BasicScheduler<P>, &Context) -> R,
    P: Park,
{
    // Ensures the run queue is placed back in the `BasicScheduler` instance
    // once `block_on` returns.`
    struct Guard<'a, P: Park> {
        context: Option<Context>,
        scheduler: &'a mut BasicScheduler<P>,
    }
    impl<P: Park> Drop for Guard<'_, P> {
        fn drop(&mut self) {
            let Context { tasks, .. } = self.context.take().expect("context missing");
            self.scheduler.tasks = Some(tasks.into_inner());
        }
    }
    // Remove `tasks` from `self` and place it in a `Context`.
    let tasks = scheduler.tasks.take().expect("invalid state");
    let guard = Guard {
        context: Some(Context {
            shared: scheduler.spawner.shared.clone(),
            tasks: RefCell::new(tasks),
        }),
        scheduler,
    };
    let context = guard.context.as_ref().unwrap();
    let scheduler = &mut *guard.scheduler;
    CURRENT.set(context, || f(scheduler, context))
}
fn enter < F , R , P > ( scheduler : & mut BasicScheduler < P > , f : F ) -> R where F : FnOnce ( & mut BasicScheduler < P > , & Context ) -> R , P : Park , { // Ensures the run queue is placed back in the `BasicScheduler` instance // once `block_on` returns.` struct Guard < ' a , P : Park > { context : Option < Context > , scheduler : & ' a mut BasicScheduler < P > , } impl < P : Park > Drop for Guard < ' _ , P > { fn drop ( & mut self ) { let Context { tasks , .. } = self . context . take ( ) . expect ( " " ) ; self . scheduler . tasks = Some ( tasks . into_inner ( ) ) ; } } // Remove `tasks` from `self` and place it in a `Context`. let tasks = scheduler . tasks . take ( ) . expect ( " " ) ; let guard = Guard { context : Some ( Context { shared : scheduler . spawner . shared . clone ( ) , tasks : RefCell :: new ( tasks ) , } ) , scheduler , } ; let context = guard . context . as_ref ( ) . unwrap ( ) ; let scheduler = & mut * guard . scheduler ; CURRENT . set ( context , | | f ( scheduler , context ) ) }
Enter the scheduler context.
Enter the scheduler context .
scheduler
&mut BasicScheduler<P>
f
F
scheduler
&mut BasicScheduler<P>
f
F