pub fn safe_read_byte(buffer: &[u8], offset: usize) -> Result<u8, IoError>Expand description
Safely reads a single byte from a buffer with bounds checking
This is a convenience function for reading a single byte with proper bounds checking.
§Arguments
buffer- The buffer to read fromoffset- Offset of the byte to read
§Returns
Returns the byte at the specified offset on success, or an IoError if
the access would be out of bounds.
§Errors
This function will return an error if the offset is beyond the buffer size.
§Examples
use libmagic_rs::io::safe_read_byte;
let buffer = b"Hello";
let byte = safe_read_byte(buffer, 0)?;
assert_eq!(byte, b'H');