pub struct StringTable { /* private fields */ }Expand description
A string table containing key-value pairs.
String tables store game data in a table format where each row has a key (string) and optional value (binary data). They’re used for various purposes like tracking active modifiers, entity names, particle systems, etc.
§Usage Patterns
§Accessing player data
use source2_demo::prelude::*;
use source2_demo::proto::CMsgPlayerInfo;
let userinfo = ctx.string_tables().get_by_name("userinfo")?;
let row = userinfo.get_row_by_index(0)?;
if let Some(data) = row.value() {
let player_info = CMsgPlayerInfo::decode(data)?;
println!("Player: {}", player_info.name());
}§Listing all entries
use source2_demo::prelude::*;
for row in table.iter() {
println!("Key: {}", row.key());
if let Some(value) = row.value() {
println!(" Value size: {} bytes", value.len());
}
}Implementations§
Source§impl StringTable
impl StringTable
Sourcepub fn iter(&self) -> impl Iterator<Item = &StringTableRow>
pub fn iter(&self) -> impl Iterator<Item = &StringTableRow>
Returns an iterator over all rows in the string table.
This allows you to inspect all key-value pairs stored in the table.
§Examples
use source2_demo::prelude::*;
let table = ctx.string_tables().get_by_name("ActiveModifiers")?;
for row in table.iter() {
println!("Key: {}", row.key());
if let Some(value) = row.value() {
println!(" Value size: {} bytes", value.len());
}
}Sourcepub fn get_row_by_index(
&self,
idx: usize,
) -> Result<&StringTableRow, StringTableError>
pub fn get_row_by_index( &self, idx: usize, ) -> Result<&StringTableRow, StringTableError>
Gets a specific row by its index in the string table.
Each string table is essentially a list of key-value pairs. This retrieves the row at the specified position.
§Arguments
idx- The row index (0-based)
§Errors
Returns StringTableError::RowNotFoundByIndex if the index is out of bounds.
§Examples
use source2_demo::prelude::*;
let userinfo = ctx.string_tables().get_by_name("userinfo")?;
// Get player info at slot 0
let row = userinfo.get_row_by_index(0)?;
println!("Slot 0 key: {}", row.key());Trait Implementations§
Source§impl Clone for StringTable
impl Clone for StringTable
Source§fn clone(&self) -> StringTable
fn clone(&self) -> StringTable
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 StringTable
impl Default for StringTable
Source§fn default() -> StringTable
fn default() -> StringTable
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for StringTable
impl !RefUnwindSafe for StringTable
impl !Send for StringTable
impl !Sync for StringTable
impl Unpin for StringTable
impl UnsafeUnpin for StringTable
impl UnwindSafe for StringTable
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