pub fn try_swap(&self, value: T) -> Result<T, T> {
        let res = self.mark.compare_exchange_weak(false, true, Ordering::AcqRel, Ordering::Acquire);
        if res.unwrap_or_else(identity) {
            Err(value) //other thread interfered
        } else {
            //we know for sure we are only thread writing to this location
            //swap values
            unsafe {
                let first = self.cell.get().read_volatile();
                self.cell.get().write_volatile(ManuallyDrop::new(value));
                self.mark.store(false, Ordering::Release);
                Ok(ManuallyDrop::into_inner(first))
            }
        }
    }
/// Tries to swap the value inside cell.
///
/// When successful returns `Ok` with previous value. In case of failure, returns `Err` with
/// argument passed to it, returning ownership of value.
///
/// 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 swap value again until success.
Tries to swap the value inside cell.
When successful returns `Ok` with previous value. In case of failure, returns `Err` with
argument passed to it, returning ownership of value.

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 swap value again until success.
Tries to swap the value inside cell . When successful returns ` Ok ` with previous value . In case of failure returns ` Err ` with argument passed to it returning ownership of value . 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 swap value again until success .
pub fn try_swap(&self, value: T) -> Result<T, T> {
        let res = self.mark.compare_exchange_weak(false, true, Ordering::AcqRel, Ordering::Acquire);
        if res.unwrap_or_else(identity) {
            Err(value) //other thread interfered
        } else {
            //we know for sure we are only thread writing to this location
            //swap values
            unsafe {
                let first = self.cell.get().read_volatile();
                self.cell.get().write_volatile(ManuallyDrop::new(value));
                self.mark.store(false, Ordering::Release);
                Ok(ManuallyDrop::into_inner(first))
            }
        }
    }
pub fn try_swap ( & self , value : T ) -> Result < T , T > { let res = self . mark . compare_exchange_weak ( false , true , Ordering :: AcqRel , Ordering :: Acquire ) ; if res . unwrap_or_else ( identity ) { Err ( value ) //other thread interfered } else { //we know for sure we are only thread writing to this location //swap values unsafe { let first = self . cell . get ( ) . read_volatile ( ) ; self . cell . get ( ) . write_volatile ( ManuallyDrop :: new ( value ) ) ; self . mark . store ( false , Ordering :: Release ) ; Ok ( ManuallyDrop :: into_inner ( first ) ) } } }
Tries to swap the value inside cell.
Tries to swap the value inside cell .
&self
value
T
&self
value
T