pub trait Table: Send + Sync {
Show 13 methods
// Required methods
fn name(&self) -> &str;
fn definition(&self) -> &Definition;
fn patches(&self) -> &DefinitionPatch;
fn data(&self) -> Cow<'_, [Vec<DecodedData>]>;
fn data_mut(&mut self) -> &mut Vec<Vec<DecodedData>>;
fn set_name(&mut self, val: String);
fn set_definition(&mut self, new_definition: &Definition);
fn set_data(&mut self, data: &[Vec<DecodedData>]) -> Result<()>;
fn column_position_by_name(&self, column_name: &str) -> Option<usize>;
fn is_empty(&self) -> bool;
fn len(&self) -> usize;
fn rows_containing_data(
&self,
column_name: &str,
data: &str,
) -> Option<(usize, Vec<usize>)>;
// Provided method
fn new_row(&self) -> Vec<DecodedData> { ... }
}Expand description
Abstract interface for table-like data structures.
This trait defines the common interface for all table implementations in RPFM.
Tables are row-based data structures with typed columns defined by a Definition.
§Thread Safety
Implementations must be Send + Sync to support concurrent access and modification
in multi-threaded environments.
§Implementations
local::TableInMemory- In-memory table with full encode/decode support
§Usage
fn process_table<T: Table>(table: &T) {
// Access metadata
let name = table.name();
let definition = table.definition();
// Iterate rows
for row in table.data().iter() {
// Process each row
}
}Required Methods§
Sourcefn definition(&self) -> &Definition
fn definition(&self) -> &Definition
Returns the table’s schema definition.
The definition specifies column structure, types, constraints, and version information.
Sourcefn patches(&self) -> &DefinitionPatch
fn patches(&self) -> &DefinitionPatch
Returns definition patches applied to this table.
Patches allow runtime modification of definitions for specific tables without changing the base schema.
Sourcefn data(&self) -> Cow<'_, [Vec<DecodedData>]>
fn data(&self) -> Cow<'_, [Vec<DecodedData>]>
Returns the table’s row data.
Returns a Cow to allow zero-copy access for immutable operations while
supporting owned data when needed.
Sourcefn data_mut(&mut self) -> &mut Vec<Vec<DecodedData>>
fn data_mut(&mut self) -> &mut Vec<Vec<DecodedData>>
Returns a mutable reference to the table’s row data.
§Safety
Using this method makes you responsible for maintaining data validity:
- Each row must have the correct number of columns
- Each cell must match the type specified in the definition
- Data integrity is not automatically validated
Sourcefn set_definition(&mut self, new_definition: &Definition)
fn set_definition(&mut self, new_definition: &Definition)
Replaces the table’s definition and migrates data to match the new schema.
This method enables version migration: converting table data from one schema version to another. When the definition changes:
- New columns are added with default values
- Removed columns are dropped
- Type changes are converted where possible
- Data is validated against the new schema
§Use Cases
- Updating tables after game patches change the schema
- Converting tables between game versions
- Applying definition modifications from patches
Sourcefn column_position_by_name(&self, column_name: &str) -> Option<usize>
fn column_position_by_name(&self, column_name: &str) -> Option<usize>
Returns the column index for a given column name.
Returns None if no column with the specified name exists.
Column names are case-sensitive.
Provided Methods§
Sourcefn new_row(&self) -> Vec<DecodedData>
fn new_row(&self) -> Vec<DecodedData>
Creates a new empty row with default values for all columns.
Default values are determined by:
- Field-specific default values from the definition/patches
- Type-specific defaults (0 for numbers, empty string for text, false for booleans)