/// If the buffer has been exhausted, fetch a new block of data to replenish the buffer.
If the buffer has been exhausted, fetch a new block of data to replenish the buffer.
If the buffer has been exhausted fetch a new block of data to replenish the buffer .
fn fetch(&mut self) -> io::Result<()> {
        // Only fetch when the ring buffer is empty.
        if self.is_buffer_exhausted() {
            // Split the vector at the write position to get slices of the two contiguous regions of
            // the ring buffer.
            let (vec1, vec0) = self.ring.split_at_mut(self.write_pos);
            // If the first contiguous region of the ring buffer starting from the write position
            // has sufficient space to service the entire read do a simple read into that region's
            // slice.
            let actual_read_len = if vec0.len() >= self.read_block_len {
                self.inner.read(&mut vec0[..self.read_block_len])?
            }
            else {
                // Otherwise, perform a vectored read into the two contiguous region slices.
                let rem = self.read_block_len - vec0.len();
                let ring_vectors = &mut [
                    IoSliceMut::new(vec0),
                    IoSliceMut::new(&mut vec1[..rem]),
                ];
                self.inner.read_vectored(ring_vectors)?
            };
            // Increment the write position, taking into account wrap-around.
            self.write_pos = (self.write_pos + actual_read_len) & self.ring_mask;
            // Update the stream position accounting.
            self.abs_pos += actual_read_len as u64;
            self.rel_pos += actual_read_len as u64;
            // Grow the read block length exponentially to reduce the overhead of buffering on
            // consecutive seeks.
            self.read_block_len = cmp::min(self.read_block_len << 1, Self::MAX_BLOCK_LEN);
        }
        Ok(())
    }
fn fetch ( & mut self ) -> io :: Result < ( ) > { // Only fetch when the ring buffer is empty. if self . is_buffer_exhausted ( ) { // Split the vector at the write position to get slices of the two contiguous regions of // the ring buffer. let ( vec1 , vec0 ) = self . ring . split_at_mut ( self . write_pos ) ; // If the first contiguous region of the ring buffer starting from the write position // has sufficient space to service the entire read do a simple read into that region's // slice. let actual_read_len = if vec0 . len ( ) >= self . read_block_len { self . inner . read ( & mut vec0 [ .. self . read_block_len ] ) ? } else { // Otherwise, perform a vectored read into the two contiguous region slices. let rem = self . read_block_len - vec0 . len ( ) ; let ring_vectors = & mut [ IoSliceMut :: new ( vec0 ) , IoSliceMut :: new ( & mut vec1 [ .. rem ] ) , ] ; self . inner . read_vectored ( ring_vectors ) ? } ; // Increment the write position, taking into account wrap-around. self . write_pos = ( self . write_pos + actual_read_len ) & self . ring_mask ; // Update the stream position accounting. self . abs_pos += actual_read_len as u64 ; self . rel_pos += actual_read_len as u64 ; // Grow the read block length exponentially to reduce the overhead of buffering on // consecutive seeks. self . read_block_len = cmp :: min ( self . read_block_len << 1 , Self :: MAX_BLOCK_LEN ) ; } Ok ( ( ) ) }
If the buffer has been exhausted, fetch a new block of data to replenish the buffer.
If the buffer has been exhausted fetch a new block of data to replenish the buffer .
&mut self