pub struct StringTable { /* private fields */ }strings only.Expand description
A struct for storing strings without duplicates.
Add strings to the table with insert. The
returned usize can be used to read the string
back from the table’s byte representation.
Use as_bytes to obtain a byte representation of a StringTable.
The byte representation is the concatenation of the strings that have been added to the table,
with each individual string prefixed with its length in LEB128 encoding.
The byte representation contains each string only once.
§Example
use watto::StringTable;
let mut table = StringTable::new();
let foo_offset = table.insert("foo");
let bar_offset = table.insert("bar");
let string_bytes = table.as_bytes();
assert_eq!(StringTable::read(string_bytes, foo_offset).unwrap(), "foo");
assert_eq!(StringTable::read(string_bytes, bar_offset).unwrap(), "bar");Implementations§
Source§impl StringTable
impl StringTable
Sourcepub fn from_bytes(buffer: &[u8]) -> Result<Self, ReadStringError>
pub fn from_bytes(buffer: &[u8]) -> Result<Self, ReadStringError>
Initializes a StringTable from a previously serialized representation.
This essentially reverses the as_bytes call.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns a byte slice containing the concatenation of the strings that have been
added to this StringTable.
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Returns a byte vector containing the concatenation of the strings that have been
added to this StringTable.
This consumes the StringTable.
Trait Implementations§
Source§impl Clone for StringTable
impl Clone for StringTable
Source§fn clone(&self) -> StringTable
fn clone(&self) -> StringTable
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more