pub struct StringTable { /* private fields */ }
Available on crate feature 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

Initializes an empty StringTable.

Insert a string into this StringTable.

Returns an offset that can be used to retrieve the inserted string with read after serializing this table with as_bytes.

Returns a byte slice containing the concatenation of the strings that have been added to this StringTable.

Returns a byte vector containing the concatenation of the strings that have been added to this StringTable.

This consumes the StringTable.

Returns the string stored at the given offset in the byte slice, if any.

Use this to retrieve a string that was previously inserted into a StringTable.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.