pub fn read<R>(&self, f: impl FnOnce(&T) -> R) -> R {
        let active = self.arrive();

        // depending on which side is active, give it the reader
        let result = if active == ActiveSide::Left {
            unsafe { f(& (*self.left.get())) }
        } else {
            unsafe { f(& (*self.right.get())) }
        };

        self.depart(active);
        result
    }
/// Takes a function and injects the current read side into the function
///
/// # 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.read(|x| {
///     let entry = x.get(&5);
///     dbg!(entry);
/// })
/// ```
Takes a function and injects the current read side into the function
Takes a function and injects the current read side into the function
pub fn read<R>(&self, f: impl FnOnce(&T) -> R) -> R {
        let active = self.arrive();
        // depending on which side is active, give it the reader
        let result = if active == ActiveSide::Left {
            unsafe { f(& (*self.left.get())) }
        } else {
            unsafe { f(& (*self.right.get())) }
        };
        self.depart(active);
        result
    }
pub fn read < R > ( & self , f : impl FnOnce ( & T ) -> R ) -> R { let active = self . arrive ( ) ; // depending on which side is active, give it the reader let result = if active == ActiveSide :: Left { unsafe { f ( & ( * self . left . get ( ) ) ) } } else { unsafe { f ( & ( * self . right . get ( ) ) ) } } ; self . depart ( active ) ; result }
Takes a function and injects the current read side into the function
Takes a function and injects the current read side into the function
&self
f
impl FnOnce(&T) -> R
&self
f
impl FnOnce(&T) -> R
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.read(|x| {
let entry = x.get(&5);
dbg!(entry);
})
```
` ` ` 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 . read ( |x| { let entry = x . get ( &5 ) ; dbg! ( entry ) ; } ) ` ` `