Skip to main content

Table

Trait Table 

Source
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

§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§

Source

fn name(&self) -> &str

Returns the table name (e.g., “units_tables”, “factions_tables”).

Source

fn definition(&self) -> &Definition

Returns the table’s schema definition.

The definition specifies column structure, types, constraints, and version information.

Source

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.

Source

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.

Source

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
Source

fn set_name(&mut self, val: String)

Sets the table name.

Source

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
Source

fn set_data(&mut self, data: &[Vec<DecodedData>]) -> Result<()>

Replaces the table’s data with the provided rows.

§Validation

This method validates that:

  • Each row has the correct number of columns
  • Each cell matches the expected type from the definition
§Errors

Returns an error if validation fails.

Source

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.

Source

fn is_empty(&self) -> bool

Returns true if the table contains no rows.

Source

fn len(&self) -> usize

Returns the number of rows in the table.

Source

fn rows_containing_data( &self, column_name: &str, data: &str, ) -> Option<(usize, Vec<usize>)>

This function tries to find all rows with the provided data, if they exists in this table.

Provided Methods§

Source

fn new_row(&self) -> Vec<DecodedData>

Creates a new empty row with default values for all columns.

Default values are determined by:

  1. Field-specific default values from the definition/patches
  2. Type-specific defaults (0 for numbers, empty string for text, false for booleans)

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§