pub fn write(&self, f: impl FnOnce(&mut T)) {
        // Make sure that we are the only ones that manipulate the structure
        while self
                .exclusive_write
                .compare_exchange_weak(
                    true, false,
                    Ordering::SeqCst, Ordering::SeqCst
                )
                .is_err() {}

        // When the left side is currently active, inject the right side.
        // When the right side is currently active, inject the left side.
        if self.active_side.get() == ActiveSide::Right {
            unsafe { f(&mut (*self.left.get())) }
        } else {
            unsafe { f(&mut (*self.right.get())) }
        }

        // Unlock datastructure
        self.exclusive_write.store(true, Ordering::SeqCst);
    }
/// Takes a function and injects the current write side into the function
///
/// The caller MUST call the [LeftRight::commit] function when the changes
/// should be commited.
///
/// # Example:
/// ``` rust
/// use cachem::LeftRight;
/// use std::collections::HashMap;
/// 
/// // Creates a new [LeftRight] instance, the [HashMap] can be replace
/// // with any other type
/// let left_right = LeftRight::<HashMap<u32, u32>>::default();
/// // x contains the HashMap or any other configured type
/// left_right.write(|x|
///     { x.entry(5).and_modify(|x| *x += 1).or_insert(0); }
/// );
/// ```
///
Takes a function and injects the current write side into the function
The caller MUST call the [LeftRight::commit] function when the changes
should be commited.
Takes a function and injects the current write side into the function The caller MUST call the [ LeftRight :: commit ] function when the changes should be commited .
pub fn write(&self, f: impl FnOnce(&mut T)) {
        // Make sure that we are the only ones that manipulate the structure
        while self
                .exclusive_write
                .compare_exchange_weak(
                    true, false,
                    Ordering::SeqCst, Ordering::SeqCst
                )
                .is_err() {}
        // When the left side is currently active, inject the right side.
        // When the right side is currently active, inject the left side.
        if self.active_side.get() == ActiveSide::Right {
            unsafe { f(&mut (*self.left.get())) }
        } else {
            unsafe { f(&mut (*self.right.get())) }
        }
        // Unlock datastructure
        self.exclusive_write.store(true, Ordering::SeqCst);
    }
pub fn write ( & self , f : impl FnOnce ( & mut T ) ) { // Make sure that we are the only ones that manipulate the structure while self . exclusive_write . compare_exchange_weak ( true , false , Ordering :: SeqCst , Ordering :: SeqCst ) . is_err ( ) { } // When the left side is currently active, inject the right side. // When the right side is currently active, inject the left side. if self . active_side . get ( ) == ActiveSide :: Right { unsafe { f ( & mut ( * self . left . get ( ) ) ) } } else { unsafe { f ( & mut ( * self . right . get ( ) ) ) } } // Unlock datastructure self . exclusive_write . store ( true , Ordering :: SeqCst ) ; }
Takes a function and injects the current write side into the function
The caller MUST call the [LeftRight::commit] function when the changes
should be commited.
Takes a function and injects the current write side into the function The caller MUST call the [ LeftRight :: commit ] function when the changes should be commited .
&self
f
impl FnOnce(&mut T)
&self
f
impl FnOnce(&mut T)
example:
``` rust
use cachem::LeftRight;
use std::collections::HashMap.

Creates a new [LeftRight] instance, the [HashMap] can be replace
with any other type
let left_right = LeftRight::>::default();
x contains the HashMap or any other configured type
left_right.write(|x|
{ x.entry(5).and_modify(|x| *x += 1).or_insert(0); }
);
```
` ` ` rust use cachem :: LeftRight ; use std :: collections :: HashMap . Creates a new [ LeftRight ] instance the [ HashMap ] can be replace with any other type let left_right = LeftRight :: > :: default () ; x contains the HashMap or any other configured type left_right . write ( |x| { x . entry ( 5 ) . and_modify ( |x| * x + = 1 ) . or_insert ( 0 ) ; } ) ; ` ` `