fn read_exact(&mut self, mut buf: &mut [u8]) -> io::Result<()> {
        if self.buffer().len() >= buf.len() {
            buf.copy_from_slice(&self.buffer()[..buf.len()]);
            self.consume(buf.len());
            return Ok(());
        }

        while !buf.is_empty() {
            match self.read(buf) {
                Ok(0) => break,
                Ok(n) => {
                    let tmp = buf;
                    buf = &mut tmp[n..];
                }
                Err(e) if e.kind() == ErrorKind::Interrupted => {}
                Err(e) => return Err(e),
            }
        }

        if !buf.is_empty() {
            Err(io::Error::new(ErrorKind::UnexpectedEof, "failed to fill whole buffer"))
        } else {
            Ok(())
        }
    }
// Small read_exacts from a BufReader are extremely common when used with a deserializer.
// The default implementation calls read in a loop, which results in surprisingly poor code
// generation for the common path where the buffer has enough bytes to fill the passed-in
// buffer.
Small read_exacts from a BufReader are extremely common when used with a deserializer.
The default implementation calls read in a loop, which results in surprisingly poor code
generation for the common path where the buffer has enough bytes to fill the passed-in
buffer.
Small read_exacts from a BufReader are extremely common when used with a deserializer . The default implementation calls read in a loop which results in surprisingly poor code generation for the common path where the buffer has enough bytes to fill the passed - in buffer .
fn read_exact(&mut self, mut buf: &mut [u8]) -> io::Result<()> {
        if self.buffer().len() >= buf.len() {
            buf.copy_from_slice(&self.buffer()[..buf.len()]);
            self.consume(buf.len());
            return Ok(());
        }
        while !buf.is_empty() {
            match self.read(buf) {
                Ok(0) => break,
                Ok(n) => {
                    let tmp = buf;
                    buf = &mut tmp[n..];
                }
                Err(e) if e.kind() == ErrorKind::Interrupted => {}
                Err(e) => return Err(e),
            }
        }
        if !buf.is_empty() {
            Err(io::Error::new(ErrorKind::UnexpectedEof, "failed to fill whole buffer"))
        } else {
            Ok(())
        }
    }
fn read_exact ( & mut self , mut buf : & mut [ u8 ] ) -> io :: Result < ( ) > { if self . buffer ( ) . len ( ) >= buf . len ( ) { buf . copy_from_slice ( & self . buffer ( ) [ .. buf . len ( ) ] ) ; self . consume ( buf . len ( ) ) ; return Ok ( ( ) ) ; } while ! buf . is_empty ( ) { match self . read ( buf ) { Ok ( 0 ) => break , Ok ( n ) => { let tmp = buf ; buf = & mut tmp [ n .. ] ; } Err ( e ) if e . kind ( ) == ErrorKind :: Interrupted => { } Err ( e ) => return Err ( e ) , } } if ! buf . is_empty ( ) { Err ( io :: Error :: new ( ErrorKind :: UnexpectedEof , " " ) ) } else { Ok ( ( ) ) } }
Small read_exacts from a BufReader are extremely common when used with a deserializer.
Small read_exacts from a BufReader are extremely common when used with a deserializer .
&mut self
buf
&mut [u8]
&mut self
buf
&mut [u8]