pub fn strn(buf: &[u8]) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Expand description
Reads an optionally nul-terminated string from byte buffer.
Returns the slice split before the nul byte and the whole slice if no nul byte is found.
Analog to the strn*
family of C string functions.
Examples
use pelite::util::strn;
let buf: &[u8; 8] = b"STRING\0\0";
assert_eq!(strn(buf), b"STRING");
let buf: &[u8; 4] = b"FOUR";
assert_eq!(strn(buf), b"FOUR");