pub struct StringTable<'a> { /* private fields */ }Expand description
String table for zero-copy parsing of string data
This struct wraps a byte slice containing null-terminated UTF-8 strings. Strings can be extracted by offset and length without copying.
§Examples
use aion_context::string_table::StringTable;
let data = b"Genesis\0Version 2\0";
let table = StringTable::new(data).unwrap();
let s1 = table.get(0, 7).unwrap();
assert_eq!(s1, "Genesis");
let s2 = table.get(8, 9).unwrap();
assert_eq!(s2, "Version 2");Implementations§
Source§impl<'a> StringTable<'a>
impl<'a> StringTable<'a>
Sourcepub fn get(&self, offset: u64, length: u32) -> Result<&'a str>
pub fn get(&self, offset: u64, length: u32) -> Result<&'a str>
Get a string by offset and length
§Arguments
offset- Byte offset to the first character of the stringlength- Length of the string in bytes (excluding null terminator)
§Errors
Returns an error if:
- Offset + length exceeds table bounds
- The extracted bytes are not valid UTF-8
- The string is not properly null-terminated
§Examples
use aion_context::string_table::StringTable;
let data = b"First\0Second\0Third\0";
let table = StringTable::new(data).unwrap();
assert_eq!(table.get(0, 5).unwrap(), "First");
assert_eq!(table.get(6, 6).unwrap(), "Second");
assert_eq!(table.get(13, 5).unwrap(), "Third");Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Get total size of the string table in bytes
§Examples
use aion_context::string_table::StringTable;
let data = b"Alpha\0Beta\0";
let table = StringTable::new(data).unwrap();
assert_eq!(table.len(), 11);Trait Implementations§
Source§impl<'a> Clone for StringTable<'a>
impl<'a> Clone for StringTable<'a>
Source§fn clone(&self) -> StringTable<'a>
fn clone(&self) -> StringTable<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a> Debug for StringTable<'a>
impl<'a> Debug for StringTable<'a>
impl<'a> Copy for StringTable<'a>
Auto Trait Implementations§
impl<'a> Freeze for StringTable<'a>
impl<'a> RefUnwindSafe for StringTable<'a>
impl<'a> Send for StringTable<'a>
impl<'a> Sync for StringTable<'a>
impl<'a> Unpin for StringTable<'a>
impl<'a> UnsafeUnpin for StringTable<'a>
impl<'a> UnwindSafe for StringTable<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more