pub struct Strtab<'a> { /* private fields */ }
Expand description
A common string table format which is indexed by byte offsets (and not
member index). Constructed using parse
with your choice of delimiter. Please be careful.
Implementations§
source§impl<'a> Strtab<'a>
impl<'a> Strtab<'a>
sourcepub fn new(bytes: &'a [u8], delim: u8) -> Self
pub fn new(bytes: &'a [u8], delim: u8) -> Self
Construct a new strtab with bytes
as the backing string table, using delim
as the delimiter between entries
sourcepub unsafe fn from_raw(ptr: *const u8, size: usize, delim: u8) -> Strtab<'a>
pub unsafe fn from_raw(ptr: *const u8, size: usize, delim: u8) -> Strtab<'a>
Construct a strtab from a ptr
, and a size
, using delim
as the delimiter
Safety
This function creates a Strtab
directly from a raw pointer and size
sourcepub fn parse(
bytes: &'a [u8],
offset: usize,
len: usize,
delim: u8
) -> Result<Strtab<'a>>
pub fn parse( bytes: &'a [u8], offset: usize, len: usize, delim: u8 ) -> Result<Strtab<'a>>
Parses a strtab from bytes
at offset
with len
size as the backing string table, using delim
as the delimiter
sourcepub fn to_vec(&self) -> Result<Vec<&'a str>>
pub fn to_vec(&self) -> Result<Vec<&'a str>>
Converts the string table to a vector, with the original delim
used to separate the strings
sourcepub fn get(&self, offset: usize) -> Option<Result<&'a str>>
pub fn get(&self, offset: usize) -> Option<Result<&'a str>>
Safely parses and gets a str reference from the backing bytes starting at byte offset
.
If the index is out of bounds, None
is returned.
Requires feature = "alloc"
sourcepub fn get_unsafe(&self, offset: usize) -> Option<&'a str>
pub fn get_unsafe(&self, offset: usize) -> Option<&'a str>
Gets a str reference from the backing bytes starting at byte offset
.
If the index is out of bounds, None
is returned. Panics if bytes are invalid UTF-8.