Skip to main content

StringTables

Struct StringTables 

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

Container managing all string tables in a replay.

String tables store game data in key-value pairs organized by table name.

§Examples

§Iterating all tables

use source2_demo::prelude::*;

for table in ctx.string_tables().iter() {
    println!("Table: {} ({} rows)", table.name(), table.iter().count());
}

§Accessing a specific table

use source2_demo::prelude::*;

// Get by table name
let modifiers = ctx.string_tables().get_by_name("ActiveModifiers")?;
println!("Active modifiers: {}", modifiers.iter().count());

// Get by table ID
let table = ctx.string_tables().get_by_id(0)?;
println!("Table at index 0: {}", table.name());

§Extracting player data from userinfo

use source2_demo::prelude::*;
use source2_demo::proto::CMsgPlayerInfo;

let userinfo = ctx.string_tables().get_by_name("userinfo")?;

// Read player info for slot 0
let player_row = userinfo.get_row_by_index(0)?;
if let Some(data) = player_row.value() {
    let player_info = CMsgPlayerInfo::decode(data)?;
    println!("Player: {}", player_info.name());
}

Implementations§

Source§

impl StringTables

Source

pub fn iter(&self) -> impl Iterator<Item = &StringTable>

Returns an iterator over all string tables.

Useful for discovering available tables or performing operations on all tables regardless of their names.

Source

pub fn get_by_id(&self, id: usize) -> Result<&StringTable, StringTableError>

Gets a string table by its numeric ID/index.

§Arguments
  • id - The numeric index of the table
§Errors

Returns StringTableError::TableNotFoundById if no table exists at the given ID.

§Examples
use source2_demo::prelude::*;

let table = ctx.string_tables().get_by_id(5)?;
println!("Table: {}", table.name());
Source

pub fn get_by_name(&self, name: &str) -> Result<&StringTable, StringTableError>

Gets a string table by its name.

This is the most common way to access string tables since you typically know which table (e.g., “userinfo”, “ActiveModifiers”) you need.

§Arguments
  • name - The name of the table (case-sensitive)
§Errors

Returns StringTableError::TableNotFoundByName if no table with the given name exists.

§Examples
use source2_demo::prelude::*;

// Get the userinfo table (contains player info)
let userinfo = ctx.string_tables().get_by_name("userinfo")?;

// Get the active modifiers table
let modifiers = ctx.string_tables().get_by_name("ActiveModifiers")?;

Trait Implementations§

Source§

impl Clone for StringTables

Source§

fn clone(&self) -> StringTables

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for StringTables

Source§

fn default() -> StringTables

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

impl Display for StringTables

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 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.