read_str_checked

Function read_str_checked 

Source
pub unsafe fn read_str_checked(
    buffer: &[u8],
    offset: usize,
    length: usize,
) -> Result<&str, &'static str>
Expand description

Helper to read a UTF-8 string from buffer with known length (SAFE PATH - validates UTF-8)

This validates UTF-8 on every read. Use for untrusted databases. Slower than read_str_unchecked but prevents undefined behavior.

ยงSafety

Caller must ensure:

  • offset + length <= buffer.len()
  • Length is correct

UTF-8 validation is performed, so invalid UTF-8 returns an error.