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
impl StringTables
Sourcepub fn iter(&self) -> impl Iterator<Item = &StringTable>
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.
Sourcepub fn get_by_id(&self, id: usize) -> Result<&StringTable, StringTableError>
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());Sourcepub fn get_by_name(&self, name: &str) -> Result<&StringTable, StringTableError>
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
impl Clone for StringTables
Source§fn clone(&self) -> StringTables
fn clone(&self) -> StringTables
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for StringTables
impl Default for StringTables
Source§fn default() -> StringTables
fn default() -> StringTables
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for StringTables
impl !RefUnwindSafe for StringTables
impl !Send for StringTables
impl !Sync for StringTables
impl Unpin for StringTables
impl UnsafeUnpin for StringTables
impl UnwindSafe for StringTables
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more