Skip to main content

RawTable

Struct RawTable 

Source
pub struct RawTable {
    pub definition: Option<RawDefinition>,
    pub rows: Vec<RawTableRow>,
}
Expand description

Complete table data parsed from Assembly Kit XML files.

This represents an entire table including its structure definition and all row data. Corresponds to a .xml data file in the Assembly Kit (e.g., units_tables.xml).

§Structure

The table contains:

  • An optional definition (field structure) - typically populated during parsing
  • All rows of data from the XML file

§Usage

After parsing with RawTable::read() or RawTable::read_all(), the table can be converted to RPFM’s internal formats:

Fields§

§definition: Option<RawDefinition>

Table structure definition (fields, types, relationships).

This is populated by combining the parsed data structure with the corresponding TWaD_ definition file.

§rows: Vec<RawTableRow>

All rows of data in the table.

Implementations§

Source§

impl RawTable

Implementation of RawTable.

Source

pub fn read_all( raw_tables_folder: &Path, version: i16, tables_to_skip: &[&str], ) -> Result<Vec<Self>>

Reads all table data files from an Assembly Kit directory.

This function scans the directory for table data XML files and parses them into RawTable instances. It first reads all table definitions, then reads the corresponding data files.

§Arguments
  • raw_tables_folder - Directory containing both definition and data files
  • version - Assembly Kit version (0-2)
  • tables_to_skip - Table names to exclude from parsing
§Returns

Returns a vector of successfully parsed tables. Tables that fail to parse or are in the skip list are excluded.

§Errors

Returns an error if:

  • The version is unsupported (not 0, 1, or 2)
  • The directory cannot be read
  • Definition files cannot be parsed
§Note

Individual table data files that fail to parse are silently skipped rather than causing the entire operation to fail.

Source

pub fn read( raw_definition: &RawDefinition, raw_table_data_folder: &Path, version: i16, ) -> Result<Self>

Parses a single Assembly Kit table data file.

Reads the XML data file corresponding to the provided definition and parses it into a RawTable. The data file must have the same name as the definition (without the TWaD_ prefix).

§Arguments
  • raw_definition - Table structure definition
  • raw_table_data_folder - Directory containing the data XML files
  • version - Assembly Kit version (0-2)
§Returns

Returns a RawTable with the definition and all parsed row data.

§Errors

Returns an error if:

§Special Cases
§translated_texts.xml

This file (present in Rome 2, Attila, Thrones) is ~400MB and not needed for schema processing, so it’s explicitly ignored.

§XML Preprocessing

Before parsing, the XML undergoes several transformations to work around serde_xml_rs limitations:

  1. Table-specific row tags are renamed to generic <rows>
  2. Field tags are renamed to <datafield> with the name as an attribute
  3. Empty fields are filled with placeholder text (removed after parsing)
Source

pub fn to_db(&self, definition: Option<&Definition>) -> Result<DB>

Converts the raw table to RPFM’s DB format.

This is a convenience wrapper around RawTable::to_table() that converts the result to a DB struct suitable for saving as a PackFile table.

§Arguments
  • definition - Optional RPFM schema definition for type validation and patching
§Returns

Returns a DB instance containing the converted table data.

§Errors

Returns an error if:

  • The table has no definition
  • Field types cannot be determined
  • Data conversion fails (e.g., invalid number format)
Source

pub fn to_table(&self, definition: Option<&Definition>) -> Result<TableInMemory>

Converts the raw table to RPFM’s in-memory table format.

This function performs the main conversion from Assembly Kit’s XML representation to RPFM’s internal table structure, including type conversion and handling of missing fields.

§Arguments
  • definition - Optional RPFM schema definition used for:
    • Type validation and patching (e.g., fixing string types on empty fields)
    • Providing default values for missing fields
§Returns

Returns a TableInMemory with all data converted to proper types.

§Errors

Returns an error if:

§Type Conversion

String values from XML are converted to typed data:

  • "true", "1"Boolean(true)
  • "123"I32(123), F32(123.0), etc.
  • "" → Appropriate default value for the type
§Missing Field Handling

Some games (Thrones, Attila, Rome 2, Shogun 2) omit empty fields from rows. This function inserts default values for any missing fields based on their type.

Trait Implementations§

Source§

impl Debug for RawTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RawTable

Source§

fn default() -> RawTable

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

impl<'de> Deserialize<'de> for RawTable

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,