pub unsafe fn handle_task<T,F>(task: &'static mut MaybeUninit<T>,flag: &'static mut u8,status: u8,
                               init: F,cx: &mut Context<'_>)->Poll<()>
    where T: Future<Output=()> + 'static, F: FnOnce()->T{
    if status != 0 {
        debug_assert!(status == CANCEL_TASK || status == RESTART_TASK || status == UNINIT_TASK);
        //drop anyways
        match *flag {
            FLAG_CREATED => {//if already initialized
                //temporary uninit/drop in case destructor unwinds
                *flag = if status == RESTART_TASK || status == UNINIT_TASK { FLAG_UNINIT } else { FLAG_DROPPED };
                task.as_mut_ptr().drop_in_place(); //drop previous value
            }
            FLAG_DROPPED if status == UNINIT_TASK => { *flag = FLAG_UNINIT }
            FLAG_UNINIT if status == CANCEL_TASK => { *flag = FLAG_DROPPED }
            _ => {}
        }
        if status == RESTART_TASK { //if should restart
            *task = MaybeUninit::new(init());
            //mark after creating task, so in case of panic propagation this will remain uninit
            *flag = FLAG_CREATED;
        } else { //if should only drop
            return Poll::Ready(()); //return now
        }
    }else{
        match *flag {
            FLAG_UNINIT =>{
                *task = MaybeUninit::new(init());
                //mark after creating task, so in case of panic propagation this will remain uninitialized
                *flag = FLAG_CREATED;
            }
            FLAG_DROPPED => return Poll::Ready(()),
            _ => {} //1 = initialized
        }
    }

    debug_assert_eq!(*flag,FLAG_CREATED);
    //statics are never moved
    let pin = Pin::new_unchecked(&mut *task.as_mut_ptr());
    let result = pin.poll(cx);
    if result.is_ready() {
        //Mark ready to avoid unsafety in case function is polled again.
        //Marking is done before drop in so when destruction panic propagates it won't cause
        //double drop on next call.
        *flag = FLAG_DROPPED;
        //static will never be used again so we can drop it
        task.as_mut_ptr().drop_in_place();
    }
    result
}
/// Implementations specific for static_config! macro. Do not use directly.
Implementations specific for static_config. macro. Do not use directly.
Implementations specific for static_config . macro . Do not use directly .
pub unsafe fn handle_task<T,F>(task: &'static mut MaybeUninit<T>,flag: &'static mut u8,status: u8,
                               init: F,cx: &mut Context<'_>)->Poll<()>
    where T: Future<Output=()> + 'static, F: FnOnce()->T{
    if status != 0 {
        debug_assert!(status == CANCEL_TASK || status == RESTART_TASK || status == UNINIT_TASK);
        //drop anyways
        match *flag {
            FLAG_CREATED => {//if already initialized
                //temporary uninit/drop in case destructor unwinds
                *flag = if status == RESTART_TASK || status == UNINIT_TASK { FLAG_UNINIT } else { FLAG_DROPPED };
                task.as_mut_ptr().drop_in_place(); //drop previous value
            }
            FLAG_DROPPED if status == UNINIT_TASK => { *flag = FLAG_UNINIT }
            FLAG_UNINIT if status == CANCEL_TASK => { *flag = FLAG_DROPPED }
            _ => {}
        }
        if status == RESTART_TASK { //if should restart
            *task = MaybeUninit::new(init());
            //mark after creating task, so in case of panic propagation this will remain uninit
            *flag = FLAG_CREATED;
        } else { //if should only drop
            return Poll::Ready(()); //return now
        }
    }else{
        match *flag {
            FLAG_UNINIT =>{
                *task = MaybeUninit::new(init());
                //mark after creating task, so in case of panic propagation this will remain uninitialized
                *flag = FLAG_CREATED;
            }
            FLAG_DROPPED => return Poll::Ready(()),
            _ => {} //1 = initialized
        }
    }
    debug_assert_eq!(*flag,FLAG_CREATED);
    //statics are never moved
    let pin = Pin::new_unchecked(&mut *task.as_mut_ptr());
    let result = pin.poll(cx);
    if result.is_ready() {
        //Mark ready to avoid unsafety in case function is polled again.
        //Marking is done before drop in so when destruction panic propagates it won't cause
        //double drop on next call.
        *flag = FLAG_DROPPED;
        //static will never be used again so we can drop it
        task.as_mut_ptr().drop_in_place();
    }
    result
}
pub unsafe fn handle_task < T , F > ( task : & ' static mut MaybeUninit < T > , flag : & ' static mut u8 , status : u8 , init : F , cx : & mut Context < ' _ > ) -> Poll < ( ) > where T : Future < Output = ( ) > + ' static , F : FnOnce ( ) -> T { if status != 0 { debug_assert ! ( status CANCEL_TASK status RESTART_TASK status UNINIT_TASK ) ; //drop anyways match * flag { FLAG_CREATED => { //if already initialized //temporary uninit/drop in case destructor unwinds * flag = if status == RESTART_TASK || status == UNINIT_TASK { FLAG_UNINIT } else { FLAG_DROPPED } ; task . as_mut_ptr ( ) . drop_in_place ( ) ; //drop previous value } FLAG_DROPPED if status == UNINIT_TASK => { * flag = FLAG_UNINIT } FLAG_UNINIT if status == CANCEL_TASK => { * flag = FLAG_DROPPED } _ => { } } if status == RESTART_TASK { //if should restart * task = MaybeUninit :: new ( init ( ) ) ; //mark after creating task, so in case of panic propagation this will remain uninit * flag = FLAG_CREATED ; } else { //if should only drop return Poll :: Ready ( ( ) ) ; //return now } } else { match * flag { FLAG_UNINIT => { * task = MaybeUninit :: new ( init ( ) ) ; //mark after creating task, so in case of panic propagation this will remain uninitialized * flag = FLAG_CREATED ; } FLAG_DROPPED => return Poll :: Ready ( ( ) ) , _ => { } //1 = initialized } } debug_assert_eq ! ( flag FLAG_CREATED ) ; //statics are never moved let pin = Pin :: new_unchecked ( & mut * task . as_mut_ptr ( ) ) ; let result = pin . poll ( cx ) ; if result . is_ready ( ) { //Mark ready to avoid unsafety in case function is polled again. //Marking is done before drop in so when destruction panic propagates it won't cause //double drop on next call. * flag = FLAG_DROPPED ; //static will never be used again so we can drop it task . as_mut_ptr ( ) . drop_in_place ( ) ; } result }
Implementations specific for static_config!
Implementations specific for static_config!
task
&'static mut MaybeUninit<T>
flag
&'static mut u8
status
u8
init
F
cx
&mut Context<'_>
task
&'static mut MaybeUninit<T>
flag
&'static mut u8
status
u8
init
F
cx
&mut Context<'_>