pub fn first_char(buf: &[u8]) -> io::Result<Option<char>> {
    match from_utf8(buf) {
        Ok(s) => Ok(s.chars().next()),
        Err(e) => {
            if e.error_len().is_some() {
                return Err(io::Error::new(io::ErrorKind::InvalidData,
                    "invalid utf-8 input received"));
            }

            let valid = e.valid_up_to();

            let s = unsafe { from_utf8_unchecked(&buf[..valid]) };
            Ok(s.chars().next())
        }
    }
}
/// Returns the first character in the buffer, if it contains any valid characters.
Returns the first character in the buffer, if it contains any valid characters.
Returns the first character in the buffer if it contains any valid characters .
pub fn first_char(buf: &[u8]) -> io::Result<Option<char>> {
    match from_utf8(buf) {
        Ok(s) => Ok(s.chars().next()),
        Err(e) => {
            if e.error_len().is_some() {
                return Err(io::Error::new(io::ErrorKind::InvalidData,
                    "invalid utf-8 input received"));
            }
            let valid = e.valid_up_to();
            let s = unsafe { from_utf8_unchecked(&buf[..valid]) };
            Ok(s.chars().next())
        }
    }
}
pub fn first_char ( buf : & [ u8 ] ) -> io :: Result < Option < char > > { match from_utf8 ( buf ) { Ok ( s ) => Ok ( s . chars ( ) . next ( ) ) , Err ( e ) => { if e . error_len ( ) . is_some ( ) { return Err ( io :: Error :: new ( io :: ErrorKind :: InvalidData , " " ) ) ; } let valid = e . valid_up_to ( ) ; let s = unsafe { from_utf8_unchecked ( & buf [ .. valid ] ) } ; Ok ( s . chars ( ) . next ( ) ) } } }
Returns the first character in the buffer, if it contains any valid characters.
Returns the first character in the buffer if it contains any valid characters .
buf
&[u8]
buf
&[u8]