pub(crate) fn ensure_read_exactly<F, R>(
    reader: &mut R,
    length: usize,
    error_message: &str,
    func: F,
) -> Result<()>
where
    F: FnOnce(&mut std::io::Cursor<Vec<u8>>) -> Result<()>,
    R: Read + ?Sized,
{
    let mut buf = vec![0u8; length];
    reader.read_exact(&mut buf)?;
    let mut cursor = std::io::Cursor::new(buf);

    func(&mut cursor)?;

    if cursor.position() != length as u64 {
        return Err(Error::invalid_length(length, &error_message));
    }
    Ok(())
}
/// Run the provided closure, ensuring that over the course of its execution, exactly `length` bytes
/// were read from the reader.
Run the provided closure, ensuring that over the course of its execution, exactly `length` bytes
were read from the reader.
Run the provided closure ensuring that over the course of its execution exactly ` length ` bytes were read from the reader .
pub(crate) fn ensure_read_exactly<F, R>(
    reader: &mut R,
    length: usize,
    error_message: &str,
    func: F,
) -> Result<()>
where
    F: FnOnce(&mut std::io::Cursor<Vec<u8>>) -> Result<()>,
    R: Read + ?Sized,
{
    let mut buf = vec![0u8; length];
    reader.read_exact(&mut buf)?;
    let mut cursor = std::io::Cursor::new(buf);
    func(&mut cursor)?;
    if cursor.position() != length as u64 {
        return Err(Error::invalid_length(length, &error_message));
    }
    Ok(())
}
pub ( crate ) fn ensure_read_exactly < F , R > ( reader : & mut R , length : usize , error_message : & str , func : F , ) -> Result < ( ) > where F : FnOnce ( & mut std :: io :: Cursor < Vec < u8 > > ) -> Result < ( ) > , R : Read + ? Sized , { let mut buf = vec ! [ 0u8 length ] ; reader . read_exact ( & mut buf ) ? ; let mut cursor = std :: io :: Cursor :: new ( buf ) ; func ( & mut cursor ) ? ; if cursor . position ( ) != length as u64 { return Err ( Error :: invalid_length ( length , & error_message ) ) ; } Ok ( ( ) ) }
Run the provided closure, ensuring that over the course of its execution, exactly `length` bytes
were read from the reader.
Run the provided closure ensuring that over the course of its execution exactly ` length ` bytes were read from the reader .
reader
&mut R
length
usize
error_message
&str
func
F
reader
&mut R
length
usize
error_message
&str
func
F