/// If there is a line available on the buffer, we remove it from the buffer
/// and return it wrapped in a `Some`; If this returns `None`, the buffer is
/// left unaltered.
If there is a line available on the buffer, we remove it from the buffer
and return it wrapped in a `Some`; If this returns `None`, the buffer is
left unaltered.
If there is a line available on the buffer we remove it from the buffer and return it wrapped in a ` Some ` ; If this returns ` None ` the buffer is left unaltered .
pub fn read_line(&mut self) -> Option<String> {
        if let Some(next_nl) = self.buf.iter().position(|c| *c == b'\n') {
            // Because Vec::split_off returns the tail; we need to split and swap
            let mut line = self.buf.split_off(next_nl + 1);
            std::mem::swap(&mut line, &mut self.buf);
            //pops the newline and carriage return, if any
            line.pop();
            if let Some(b'\r') = line.last() {
                line.pop();
            }
            String::from_utf8(line).ok()
        } else {
            None
        }
    }
pub fn read_line ( & mut self ) -> Option < String > { if let Some ( next_nl ) = self . buf . iter ( ) . position ( | c | * c == b'\n' ) { // Because Vec::split_off returns the tail; we need to split and swap let mut line = self . buf . split_off ( next_nl + 1 ) ; std :: mem :: swap ( & mut line , & mut self . buf ) ; //pops the newline and carriage return, if any line . pop ( ) ; if let Some ( b'\r' ) = line . last ( ) { line . pop ( ) ; } String :: from_utf8 ( line ) . ok ( ) } else { None } }
If there is a line available on the buffer, we remove it from the buffer
and return it wrapped in a `Some`; If this returns `None`, the buffer is
left unaltered.
If there is a line available on the buffer we remove it from the buffer and return it wrapped in a ` Some ` ; If this returns ` None ` the buffer is left unaltered .
&mut self