Function split_at_first_char

Source
pub fn split_at_first_char(buf: &[u8]) -> Option<(&str, &[u8])>
Expand description

Split buffer after the first valid utf8 character. Returns an error if buf does not start with a valid utf8 character.

Panics if buf is empty.

assert_eq!(split_at_first_char(
  &['1' as u8, '2' as u8, '3' as u8][..]),
  Some(("1", &['2' as u8, '3' as u8][..])));
assert_eq!(split_at_first_char(
  &[0x80, '2' as u8, '3' as u8][..]),
  None);