pub struct StringTable { /* private fields */ }
Expand description

A string table section in a KerbalObject file.

A module describing a string table section in a Kerbal Object file. This section stores a list of strings, which other Kerbal Object constructs can index into.

Each section contains as its first index (index 0) an empty string.

Implementations§

source§

impl StringTable

source

pub fn new(section_index: SectionIdx) -> Self

Creates a new string table section with the provided section index

source

pub fn with_capacity(amount: usize, section_index: SectionIdx) -> Self

Creates a new string table section with the provided section index, with internal data structures pre-allocated for the provided number of strings, +1 for the null string at index 0.

source

pub fn get(&self, index: StringIdx) -> Option<&String>

Gets the string at the index into this string table, or None if it doesn’t exist

source

pub fn position(&self, s: impl AsRef<str>) -> Option<StringIdx>

Locates a given string in this string table and returns the index if it does exist, or None if it doesn’t

source

pub fn strings(&self) -> Iter<'_, String>

Returns an iterator over all of the strings contained in this string table

source

pub fn add_checked(&mut self, new_str: impl Into<String>) -> StringIdx

Adds a string to this string table, but checks if it is already in this table. Returns the index of the string, if it already existed, the index is just found and returned. If it doesn’t, it is inserted and the new index is returned.

source

pub fn add(&mut self, new_str: impl Into<String>) -> StringIdx

Unconditionally adds a string to this string table and returns the index of it

source

pub fn size(&self) -> u32

The size of this string table section in bytes

source

pub fn section_index(&self) -> SectionIdx

The index of this section’s section header

source

pub fn parse( source: &mut BufferIterator<'_>, size: u32, section_index: SectionIdx ) -> Result<Self, StringTableParseError>

Parses a StringTable using the provided buffer, its expected size, and the section’s section index

source

pub fn write(&self, buf: &mut impl WritableBuffer)

Writes the binary representation of this string table to the provided buffer

Trait Implementations§

source§

impl Debug for StringTable

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.