/// Allows to read from ring buffer memory directry.
///
/// *This function is unsafe beacuse it gives access to possibly uninitialized memory
/// and transfers to the user the responsibility of manually calling destructors*
///
/// Takes a function `f` as argument.
/// `f` takes two slices of ring buffer content (the second one may be empty). First slice contains older elements.
///
/// `f` should return:
/// + On success: pair of number of elements been read, and some arbitrary data.
/// + On failure: some another arbitrary data.
///
/// On success returns data returned from `f`.
Allows to read from ring buffer memory directry.
This function is unsafe beacuse it gives access to possibly uninitialized memory
and transfers to the user the responsibility of manually calling destructors

Takes a function `f` as argument.
`f` takes two slices of ring buffer content (the second one may be empty). First slice contains older elements.

`f` should return:
+ On success: pair of number of elements been read, and some arbitrary data.
+ On failure: some another arbitrary data.

On success returns data returned from `f`.
Allows to read from ring buffer memory directry . This function is unsafe beacuse it gives access to possibly uninitialized memory and transfers to the user the responsibility of manually calling destructors Takes a function ` f ` as argument . ` f ` takes two slices of ring buffer content ( the second one may be empty ) . First slice contains older elements . ` f ` should return : + On success : pair of number of elements been read and some arbitrary data . + On failure : some another arbitrary data . On success returns data returned from ` f ` .
pub unsafe fn pop_access<R, E, F>(&mut self, f: F) -> Result<Result<(usize, R), E>, PopAccessError>
    where R: Sized, E: Sized, F: FnOnce(&mut [T], &mut [T]) -> Result<(usize, R), E> {
        let head = self.rb.head.load(Ordering::SeqCst);
        let tail = self.rb.tail.load(Ordering::SeqCst);
        let len = self.rb.data.get_ref().len();
        let ranges = if head < tail {
            Ok((head..tail, 0..0))
        } else if head > tail {
            Ok((head..len, 0..tail))
        } else {
            Err(PopAccessError::Empty)
        }?;
        let slices = (
            &mut self.rb.data.get_mut()[ranges.0],
            &mut self.rb.data.get_mut()[ranges.1],
        );
        match f(slices.0, slices.1) {
            Ok((n, r)) => {
                if n > slices.0.len() + slices.1.len() {
                    Err(PopAccessError::BadLen)
                } else {
                    let new_head = (head + n) % len;
                    self.rb.head.store(new_head, Ordering::SeqCst);
                    Ok(Ok((n, r)))
                }
            },
            Err(e) => {
                Ok(Err(e))
            }
        }
    }
pub unsafe fn pop_access < R , E , F > ( & mut self , f : F ) -> Result < Result < ( usize , R ) , E > , PopAccessError > where R : Sized , E : Sized , F : FnOnce ( & mut [ T ] , & mut [ T ] ) -> Result < ( usize , R ) , E > { let head = self . rb . head . load ( Ordering :: SeqCst ) ; let tail = self . rb . tail . load ( Ordering :: SeqCst ) ; let len = self . rb . data . get_ref ( ) . len ( ) ; let ranges = if head < tail { Ok ( ( head .. tail , 0 .. 0 ) ) } else if head > tail { Ok ( ( head .. len , 0 .. tail ) ) } else { Err ( PopAccessError :: Empty ) } ? ; let slices = ( & mut self . rb . data . get_mut ( ) [ ranges . 0 ] , & mut self . rb . data . get_mut ( ) [ ranges . 1 ] , ) ; match f ( slices . 0 , slices . 1 ) { Ok ( ( n , r ) ) => { if n > slices . 0 . len ( ) + slices . 1 . len ( ) { Err ( PopAccessError :: BadLen ) } else { let new_head = ( head + n ) % len ; self . rb . head . store ( new_head , Ordering :: SeqCst ) ; Ok ( Ok ( ( n , r ) ) ) } } , Err ( e ) => { Ok ( Err ( e ) ) } } }
Allows to read from ring buffer memory directry.
Allows to read from ring buffer memory directry .
&mut self
f
F