pub fn try_apply<F, R>(&self, func: F) -> Result<R, F> where F: FnOnce(&mut T) -> R, T: Copy {
        let res = self.mark.compare_exchange_weak(false, true, Ordering::AcqRel, Ordering::Acquire);
        if res.unwrap_or_else(identity) {
            Err(func) //other thread interfered
        } else {
            //we know for sure we are only thread writing to this location
            struct UnwindGuard<'a>(&'a AtomicBool);
            impl<'a> Drop for UnwindGuard<'a> {
                fn drop(&mut self) { //perform cleanup on normal execution and if closure panics
                    self.0.store(false, Ordering::Release);
                }
            }
            //modify value
            unsafe {
                let mut first = self.cell.get().read_volatile();
                let guard = UnwindGuard(&self.mark);
                let res = func(&mut first.deref_mut());//modify local copy to ensure volatile operations
                self.cell.get().write_volatile(first);
                drop(guard);//explicit drop
                Ok(res)
            }
        }
    }
/// Tries to perform action on value inside cell, possibly mutating it.
///
/// When successful returns `Ok` with value returned from executed function.
/// In case of failure, returns `Err` with argument passed to it,
/// returning ownership of function.
///
/// `T` is required to be copy in case if given function panics. When this occurs, the value is
/// restored to state from before applying the function and panic is propagated.
///
/// AtomicCell does not use atomic load/store/cas on contained data so that it can hold structs
/// of arbitrary size. This method might fail in case some other thread is now modifying this value.
/// In case of failure you can perform additional checks or try to apply action again until success.
Tries to perform action on value inside cell, possibly mutating it.
When successful returns `Ok` with value returned from executed function.
In case of failure, returns `Err` with argument passed to it,
returning ownership of function.

`T` is required to be copy in case if given function panics. When this occurs, the value is
restored to state from before applying the function and panic is propagated.

AtomicCell does not use atomic load/store/cas on contained data so that it can hold structs
of arbitrary size. This method might fail in case some other thread is now modifying this value.
In case of failure you can perform additional checks or try to apply action again until success.
Tries to perform action on value inside cell possibly mutating it . When successful returns ` Ok ` with value returned from executed function . In case of failure returns ` Err ` with argument passed to it returning ownership of function . ` T ` is required to be copy in case if given function panics . When this occurs the value is restored to state from before applying the function and panic is propagated . AtomicCell does not use atomic load / store / cas on contained data so that it can hold structs of arbitrary size . This method might fail in case some other thread is now modifying this value . In case of failure you can perform additional checks or try to apply action again until success .
pub fn try_apply<F, R>(&self, func: F) -> Result<R, F> where F: FnOnce(&mut T) -> R, T: Copy {
        let res = self.mark.compare_exchange_weak(false, true, Ordering::AcqRel, Ordering::Acquire);
        if res.unwrap_or_else(identity) {
            Err(func) //other thread interfered
        } else {
            //we know for sure we are only thread writing to this location
            struct UnwindGuard<'a>(&'a AtomicBool);
            impl<'a> Drop for UnwindGuard<'a> {
                fn drop(&mut self) { //perform cleanup on normal execution and if closure panics
                    self.0.store(false, Ordering::Release);
                }
            }
            //modify value
            unsafe {
                let mut first = self.cell.get().read_volatile();
                let guard = UnwindGuard(&self.mark);
                let res = func(&mut first.deref_mut());//modify local copy to ensure volatile operations
                self.cell.get().write_volatile(first);
                drop(guard);//explicit drop
                Ok(res)
            }
        }
    }
pub fn try_apply < F , R > ( & self , func : F ) -> Result < R , F > where F : FnOnce ( & mut T ) -> R , T : Copy { let res = self . mark . compare_exchange_weak ( false , true , Ordering :: AcqRel , Ordering :: Acquire ) ; if res . unwrap_or_else ( identity ) { Err ( func ) //other thread interfered } else { //we know for sure we are only thread writing to this location struct UnwindGuard < ' a > ( & ' a AtomicBool ) ; impl < ' a > Drop for UnwindGuard < ' a > { fn drop ( & mut self ) { //perform cleanup on normal execution and if closure panics self . 0 . store ( false , Ordering :: Release ) ; } } //modify value unsafe { let mut first = self . cell . get ( ) . read_volatile ( ) ; let guard = UnwindGuard ( & self . mark ) ; let res = func ( & mut first . deref_mut ( ) ) ; //modify local copy to ensure volatile operations self . cell . get ( ) . write_volatile ( first ) ; drop ( guard ) ; //explicit drop Ok ( res ) } } }
Tries to perform action on value inside cell, possibly mutating it.
Tries to perform action on value inside cell possibly mutating it .
&self
func
F
&self
func
F