Skip to main content

SharedStringTable

Struct SharedStringTable 

Source
pub struct SharedStringTable { /* private fields */ }
Expand description

Runtime shared string table for efficient string lookup and insertion.

Maintains both an ordered list of strings (for index-based lookup) and a reverse hash map (for deduplication when inserting). Also preserves rich text formatting information for round-tripping.

Implementations§

Source§

impl SharedStringTable

Source

pub fn new() -> Self

Create a new, empty shared string table.

Source

pub fn from_sst(sst: &Sst) -> Self

Build from an XML Sst struct.

Plain-text items use the t field directly. Rich-text items concatenate all run texts.

Source

pub fn to_sst(&self) -> Sst

Convert back to an XML Sst struct.

Source

pub fn get(&self, index: usize) -> Option<&str>

Get a string by its index.

Source

pub fn add(&mut self, s: &str) -> usize

Add a string, returning its index.

If the string already exists, the existing index is returned (dedup).

Source

pub fn add_rich_text(&mut self, runs: &[RichTextRun]) -> usize

Add rich text runs, returning the SST index.

The plain-text concatenation of the runs is used for deduplication.

Source

pub fn get_rich_text(&self, index: usize) -> Option<Vec<RichTextRun>>

Get rich text runs for an SST entry, if it has formatting.

Returns None for plain-text entries.

Source

pub fn len(&self) -> usize

Number of unique strings.

Source

pub fn is_empty(&self) -> bool

Returns true if the table contains no strings.

Trait Implementations§

Source§

impl Debug for SharedStringTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SharedStringTable

Source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.