pub fn copyv<S: AsRef<[u8]>>(
    src: &[S],
    dst: &[VolatileSlice],
    offset: usize,
    length: usize,
    mut dst_index: usize,
    mut dst_offset: usize,
) -> StorageResult<(usize, (usize, usize))> {
    // Validate input parameters first to protect following loop block.
    if src.is_empty() || length == 0 {
        return Ok((0, (dst_index, dst_offset)));
    } else if offset > src[0].as_ref().len()
        || dst_index >= dst.len()
        || dst_offset > dst[dst_index].len()
    {
        return Err(StorageError::MemOverflow);
    }

    let mut copied = 0;
    let mut src_offset = offset;
    'next_source: for s in src {
        let s = s.as_ref();
        let mut buffer_len = min(s.len() - src_offset, length - copied);

        loop {
            if dst_index >= dst.len() {
                return Err(StorageError::MemOverflow);
            }

            let dst_slice = &dst[dst_index];
            let buffer = &s[src_offset..src_offset + buffer_len];
            let written = dst_slice
                .write(buffer, dst_offset)
                .map_err(StorageError::VolatileSlice)?;

            copied += written;
            if dst_slice.len() - dst_offset == written {
                dst_index += 1;
                dst_offset = 0;
            } else {
                dst_offset += written;
            }

            // Move to next source buffer if the current source buffer has been exhausted.
            if written == buffer_len {
                src_offset = 0;
                continue 'next_source;
            } else {
                src_offset += written;
                buffer_len -= written;
            }
        }
    }

    Ok((copied, (dst_index, dst_offset)))
}
/// Copy from buffer slice to another buffer slice.
///
/// `offset` is where to start copy in the first buffer of source slice.
/// Up to bytes of `length` is wanted in `src`.
/// `dst_index` and `dst_slice_offset` indicate from where to start write destination.
/// Return (Total copied bytes, (Final written destination index, Final written destination offset))
Copy from buffer slice to another buffer slice.
`offset` is where to start copy in the first buffer of source slice.
Up to bytes of `length` is wanted in `src`.
`dst_index` and `dst_slice_offset` indicate from where to start write destination.
Return (Total copied bytes, (Final written destination index, Final written destination offset))
Copy from buffer slice to another buffer slice . ` offset ` is where to start copy in the first buffer of source slice . Up to bytes of ` length ` is wanted in ` src ` . ` dst_index ` and ` dst_slice_offset ` indicate from where to start write destination . Return ( Total copied bytes ( Final written destination index Final written destination offset ))
pub fn copyv<S: AsRef<[u8]>>(
    src: &[S],
    dst: &[VolatileSlice],
    offset: usize,
    length: usize,
    mut dst_index: usize,
    mut dst_offset: usize,
) -> StorageResult<(usize, (usize, usize))> {
    // Validate input parameters first to protect following loop block.
    if src.is_empty() || length == 0 {
        return Ok((0, (dst_index, dst_offset)));
    } else if offset > src[0].as_ref().len()
        || dst_index >= dst.len()
        || dst_offset > dst[dst_index].len()
    {
        return Err(StorageError::MemOverflow);
    }
    let mut copied = 0;
    let mut src_offset = offset;
    'next_source: for s in src {
        let s = s.as_ref();
        let mut buffer_len = min(s.len() - src_offset, length - copied);
        loop {
            if dst_index >= dst.len() {
                return Err(StorageError::MemOverflow);
            }
            let dst_slice = &dst[dst_index];
            let buffer = &s[src_offset..src_offset + buffer_len];
            let written = dst_slice
                .write(buffer, dst_offset)
                .map_err(StorageError::VolatileSlice)?;
            copied += written;
            if dst_slice.len() - dst_offset == written {
                dst_index += 1;
                dst_offset = 0;
            } else {
                dst_offset += written;
            }
            // Move to next source buffer if the current source buffer has been exhausted.
            if written == buffer_len {
                src_offset = 0;
                continue 'next_source;
            } else {
                src_offset += written;
                buffer_len -= written;
            }
        }
    }
    Ok((copied, (dst_index, dst_offset)))
}
pub fn copyv < S : AsRef < [ u8 ] > > ( src : & [ S ] , dst : & [ VolatileSlice ] , offset : usize , length : usize , mut dst_index : usize , mut dst_offset : usize , ) -> StorageResult < ( usize , ( usize , usize ) ) > { // Validate input parameters first to protect following loop block. if src . is_empty ( ) || length == 0 { return Ok ( ( 0 , ( dst_index , dst_offset ) ) ) ; } else if offset > src [ 0 ] . as_ref ( ) . len ( ) || dst_index >= dst . len ( ) || dst_offset > dst [ dst_index ] . len ( ) { return Err ( StorageError :: MemOverflow ) ; } let mut copied = 0 ; let mut src_offset = offset ; ' next_source : for s in src { let s = s . as_ref ( ) ; let mut buffer_len = min ( s . len ( ) - src_offset , length - copied ) ; loop { if dst_index >= dst . len ( ) { return Err ( StorageError :: MemOverflow ) ; } let dst_slice = & dst [ dst_index ] ; let buffer = & s [ src_offset .. src_offset + buffer_len ] ; let written = dst_slice . write ( buffer , dst_offset ) . map_err ( StorageError :: VolatileSlice ) ? ; copied += written ; if dst_slice . len ( ) - dst_offset == written { dst_index += 1 ; dst_offset = 0 ; } else { dst_offset += written ; } // Move to next source buffer if the current source buffer has been exhausted. if written == buffer_len { src_offset = 0 ; continue ' next_source ; } else { src_offset += written ; buffer_len -= written ; } } } Ok ( ( copied , ( dst_index , dst_offset ) ) ) }
Copy from buffer slice to another buffer slice.
Copy from buffer slice to another buffer slice .
src
&[S]
dst
&[VolatileSlice]
offset
usize
length
usize
dst_index
usize
dst_offset
usize
src
&[S]
dst
&[VolatileSlice]
offset
usize
length
usize
dst_index
usize
dst_offset
usize