Struct watto::StringTable
source · [−]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_idx = table.insert("foo");
let bar_idx = table.insert("bar");
let string_bytes = table.as_bytes();
assert_eq!(StringTable::read(string_bytes, foo_idx).unwrap(), "foo");
assert_eq!(StringTable::read(string_bytes, bar_idx).unwrap(), "bar");Implementations
sourceimpl StringTable
impl StringTable
sourcepub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [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
sourceimpl Clone for StringTable
impl Clone for StringTable
sourcefn clone(&self) -> StringTable
fn clone(&self) -> StringTable
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for StringTable
impl Debug for StringTable
sourceimpl Default for StringTable
impl Default for StringTable
sourcefn default() -> StringTable
fn default() -> StringTable
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl RefUnwindSafe for StringTable
impl Send for StringTable
impl Sync for StringTable
impl Unpin for StringTable
impl UnwindSafe for StringTable
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more