pub fn push(&mut self, src: &[u8]) -> Result<()> {
        // Error out if there's no room to push the entire slice.
        if self.len() + src.len() > Self::SIZE {
            return Err(Error::TxBufFull);
        }

        let data = self
            .data
            .get_or_insert_with(|| vec![0u8; Self::SIZE].into_boxed_slice());

        // Buffer head, as an offset into the data slice.
        let head_ofs = self.head.0 as usize % Self::SIZE;

        // Pushing a slice to this buffer can take either one or two slice copies: - one copy,
        // if the slice fits between `head_ofs` and `Self::SIZE`; or - two copies, if the
        // ring-buffer head wraps around.

        // First copy length: we can only go from the head offset up to the total buffer size.
        let len = std::cmp::min(Self::SIZE - head_ofs, src.len());
        data[head_ofs..(head_ofs + len)].copy_from_slice(&src[..len]);

        // If the slice didn't fit, the buffer head will wrap around, and pushing continues
        // from the start of the buffer (`&self.data[0]`).
        if len < src.len() {
            data[..(src.len() - len)].copy_from_slice(&src[len..]);
        }

        // Either way, we've just pushed exactly `src.len()` bytes, so that's the amount by
        // which the (wrapping) buffer head needs to move forward.
        self.head += Wrapping(src.len() as u32);

        Ok(())
    }
/// Push a byte slice onto the ring-buffer.
///
/// Either the entire source slice will be pushed to the ring-buffer, or none of it, if
/// there isn't enough room, in which case `Err(Error::TxBufFull)` is returned.
Push a byte slice onto the ring-buffer.
Either the entire source slice will be pushed to the ring-buffer, or none of it, if
there isn't enough room, in which case `Err(Error::TxBufFull)` is returned.
Push a byte slice onto the ring - buffer . Either the entire source slice will be pushed to the ring - buffer or none of it if there isn ' t enough room in which case ` Err ( Error :: TxBufFull ) ` is returned .
pub fn push(&mut self, src: &[u8]) -> Result<()> {
        // Error out if there's no room to push the entire slice.
        if self.len() + src.len() > Self::SIZE {
            return Err(Error::TxBufFull);
        }
        let data = self
            .data
            .get_or_insert_with(|| vec![0u8; Self::SIZE].into_boxed_slice());
        // Buffer head, as an offset into the data slice.
        let head_ofs = self.head.0 as usize % Self::SIZE;
        // Pushing a slice to this buffer can take either one or two slice copies: - one copy,
        // if the slice fits between `head_ofs` and `Self::SIZE`; or - two copies, if the
        // ring-buffer head wraps around.
        // First copy length: we can only go from the head offset up to the total buffer size.
        let len = std::cmp::min(Self::SIZE - head_ofs, src.len());
        data[head_ofs..(head_ofs + len)].copy_from_slice(&src[..len]);
        // If the slice didn't fit, the buffer head will wrap around, and pushing continues
        // from the start of the buffer (`&self.data[0]`).
        if len < src.len() {
            data[..(src.len() - len)].copy_from_slice(&src[len..]);
        }
        // Either way, we've just pushed exactly `src.len()` bytes, so that's the amount by
        // which the (wrapping) buffer head needs to move forward.
        self.head += Wrapping(src.len() as u32);
        Ok(())
    }
pub fn push ( & mut self , src : & [ u8 ] ) -> Result < ( ) > { // Error out if there's no room to push the entire slice. if self . len ( ) + src . len ( ) > Self :: SIZE { return Err ( Error :: TxBufFull ) ; } let data = self . data . get_or_insert_with ( | | vec ! [ 0u8 Self SIZE ] . into_boxed_slice ( ) ) ; // Buffer head, as an offset into the data slice. let head_ofs = self . head . 0 as usize % Self :: SIZE ; // Pushing a slice to this buffer can take either one or two slice copies: - one copy, // if the slice fits between `head_ofs` and `Self::SIZE`; or - two copies, if the // ring-buffer head wraps around. // First copy length: we can only go from the head offset up to the total buffer size. let len = std :: cmp :: min ( Self :: SIZE - head_ofs , src . len ( ) ) ; data [ head_ofs .. ( head_ofs + len ) ] . copy_from_slice ( & src [ .. len ] ) ; // If the slice didn't fit, the buffer head will wrap around, and pushing continues // from the start of the buffer (`&self.data[0]`). if len < src . len ( ) { data [ .. ( src . len ( ) - len ) ] . copy_from_slice ( & src [ len .. ] ) ; } // Either way, we've just pushed exactly `src.len()` bytes, so that's the amount by // which the (wrapping) buffer head needs to move forward. self . head += Wrapping ( src . len ( ) as u32 ) ; Ok ( ( ) ) }
Push a byte slice onto the ring-buffer.
Push a byte slice onto the ring - buffer .
&mut self
src
&[u8]
&mut self
src
&[u8]