pub struct Definition { /* private fields */ }Expand description
Defines the structure of a specific version of a database table.
A Definition specifies the exact binary layout and field properties for one version
of a table. Tables can have multiple definitions in a schema to support different versions
across game patches.
§Version Numbers
-1: Fake definition used internally for dependency resolution0: Unversioned files (tables without version markers in their binary format)1+: Versioned files with explicit version numbers
§Fields Processing
The raw fields list may undergo processing when accessed via fields_processed():
- Bitwise fields are expanded into multiple boolean fields
- Enum fields are converted to string fields
- RGB colour triplets are merged into single ColourRGB fields
Unless you have a specific reason to do so, it is recommended to use fields_processed() instead of fields.
§Localisation
Some tables have fields that are moved to separate LOC files during export:
localised_fieldslists these fieldslocalised_key_orderdefines the key field order for LOC keys
Implementations§
Source§impl Definition
impl Definition
Sourcepub fn version(&self) -> &i32
pub fn version(&self) -> &i32
The version number of this table definition.
See type-level documentation for version number meanings.
Sourcepub fn fields(&self) -> &Vec<Field>
pub fn fields(&self) -> &Vec<Field>
List of fields in the order they appear in the binary format.
This is the raw field list. For the processed version (with bitwise expansion,
enum conversion, etc.), use fields_processed().
Sourcepub fn localised_fields(&self) -> &Vec<Field>
pub fn localised_fields(&self) -> &Vec<Field>
Fields that are extracted to LOC files during export.
These fields contain localisable text that gets separated from the main table data when exporting said table to binary format.
Sourcepub fn localised_key_order(&self) -> &Vec<u32>
pub fn localised_key_order(&self) -> &Vec<u32>
Order of key fields when constructing localisation keys.
This specifies the order in which key fields should be concatenated when creating LOC entry keys. Only applies to processed fields.
Sourcepub fn patches(&self) -> &DefinitionPatch
pub fn patches(&self) -> &DefinitionPatch
Runtime patches applied to this definition.
These are loaded from the schema’s patch set and applied when retrieving the definition. Not serialized - they come from the schema’s patches field.
Source§impl Definition
impl Definition
Sourcepub fn version_mut(&mut self) -> &mut i32
pub fn version_mut(&mut self) -> &mut i32
The version number of this table definition.
See type-level documentation for version number meanings.
Sourcepub fn fields_mut(&mut self) -> &mut Vec<Field>
pub fn fields_mut(&mut self) -> &mut Vec<Field>
List of fields in the order they appear in the binary format.
This is the raw field list. For the processed version (with bitwise expansion,
enum conversion, etc.), use fields_processed().
Sourcepub fn localised_fields_mut(&mut self) -> &mut Vec<Field>
pub fn localised_fields_mut(&mut self) -> &mut Vec<Field>
Fields that are extracted to LOC files during export.
These fields contain localisable text that gets separated from the main table data when exporting said table to binary format.
Sourcepub fn localised_key_order_mut(&mut self) -> &mut Vec<u32>
pub fn localised_key_order_mut(&mut self) -> &mut Vec<u32>
Order of key fields when constructing localisation keys.
This specifies the order in which key fields should be concatenated when creating LOC entry keys. Only applies to processed fields.
Sourcepub fn patches_mut(&mut self) -> &mut DefinitionPatch
pub fn patches_mut(&mut self) -> &mut DefinitionPatch
Runtime patches applied to this definition.
These are loaded from the schema’s patch set and applied when retrieving the definition. Not serialized - they come from the schema’s patches field.
Source§impl Definition
impl Definition
Sourcepub fn set_version(&mut self, val: i32) -> &mut Self
pub fn set_version(&mut self, val: i32) -> &mut Self
The version number of this table definition.
See type-level documentation for version number meanings.
Sourcepub fn set_fields(&mut self, val: Vec<Field>) -> &mut Self
pub fn set_fields(&mut self, val: Vec<Field>) -> &mut Self
List of fields in the order they appear in the binary format.
This is the raw field list. For the processed version (with bitwise expansion,
enum conversion, etc.), use fields_processed().
Sourcepub fn set_localised_fields(&mut self, val: Vec<Field>) -> &mut Self
pub fn set_localised_fields(&mut self, val: Vec<Field>) -> &mut Self
Fields that are extracted to LOC files during export.
These fields contain localisable text that gets separated from the main table data when exporting said table to binary format.
Sourcepub fn set_localised_key_order(&mut self, val: Vec<u32>) -> &mut Self
pub fn set_localised_key_order(&mut self, val: Vec<u32>) -> &mut Self
Order of key fields when constructing localisation keys.
This specifies the order in which key fields should be concatenated when creating LOC entry keys. Only applies to processed fields.
Sourcepub fn set_patches(&mut self, val: DefinitionPatch) -> &mut Self
pub fn set_patches(&mut self, val: DefinitionPatch) -> &mut Self
Runtime patches applied to this definition.
These are loaded from the schema’s patch set and applied when retrieving the definition. Not serialized - they come from the schema’s patches field.
Source§impl Definition
Implementation of Definition.
impl Definition
Implementation of Definition.
Sourcepub fn new(version: i32, schema_patches: Option<&DefinitionPatch>) -> Definition
pub fn new(version: i32, schema_patches: Option<&DefinitionPatch>) -> Definition
Sourcepub fn new_with_fields(
version: i32,
fields: &[Field],
loc_fields: &[Field],
schema_patches: Option<&DefinitionPatch>,
) -> Definition
pub fn new_with_fields( version: i32, fields: &[Field], loc_fields: &[Field], schema_patches: Option<&DefinitionPatch>, ) -> Definition
Creates a new definition with the specified fields.
§Arguments
version- The version number for this definitionfields- The table’s field listloc_fields- The localised fields listschema_patches- Optional patches to apply to this definition
§Returns
Returns a new definition with the provided fields.
Sourcepub fn reference_data(
&self,
) -> BTreeMap<i32, (String, String, Option<Vec<String>>)>
pub fn reference_data( &self, ) -> BTreeMap<i32, (String, String, Option<Vec<String>>)>
Returns reference and lookup information for all fields with foreign key references.
This function extracts foreign key information from all fields in the definition that have a reference to another table.
§Returns
Returns a map where:
- Keys are field indices (as
i32) - Values are tuples of
(referenced_table, referenced_column, optional_lookup_columns)
Only fields with is_reference set are included in the result.
Sourcepub fn fields_processed(&self) -> Vec<Field>
pub fn fields_processed(&self) -> Vec<Field>
Returns the processed field list with transformations applied.
This function processes the raw field list and applies various transformations:
- Bitwise fields: Expanded into multiple boolean fields (e.g.,
flags→flags_1,flags_2, etc.) - Enum fields: Converted to StringU8 fields
- Colour fields: RGB triplets merged into single ColourRGB fields
- Numeric fields: Converted to I32 fields (with patches)
This is the field list that should be used for UI display and data editing.
§Returns
Returns the processed field list with all transformations applied.
Sourcepub fn original_field_from_processed(&self, index: usize) -> Field
pub fn original_field_from_processed(&self, index: usize) -> Field
Returns the original raw field corresponding to a processed field index.
This function maps a field from the processed field list back to its original raw field definition. This is useful when you need to access the underlying field data before transformations like bitwise expansion.
§Arguments
index- Index in the processed field list
§Returns
Returns the original field from the raw field list.
§Panics
Panics if the field is not found (which should never happen for valid indices).
§Note
This function does not work correctly with combined colour fields, as they don’t have a direct 1:1 mapping to a single raw field.
Sourcepub fn fields_processed_sorted(&self, key_first: bool) -> Vec<Field>
pub fn fields_processed_sorted(&self, key_first: bool) -> Vec<Field>
Returns the processed field list sorted by either key fields or CA order.
This function returns the processed fields sorted according to the specified criteria.
§Arguments
key_first- Iftrue, sorts key fields first, then non-key fields. Iffalse, sorts by CA order.
§Returns
Returns the sorted field list. Fields with ca_order == -1 are left in their original order
when sorting by CA order.
Sourcepub fn column_position_by_name(&self, column_name: &str) -> Option<usize>
pub fn column_position_by_name(&self, column_name: &str) -> Option<usize>
Sourcepub fn key_column_positions(&self) -> Vec<usize>
pub fn key_column_positions(&self) -> Vec<usize>
Returns the positions of all key columns in the processed field list.
§Returns
Returns a vector of indices for all fields marked as key fields.
Sourcepub fn key_column_positions_by_ca_order(&self) -> Vec<usize>
pub fn key_column_positions_by_ca_order(&self) -> Vec<usize>
Returns the positions of all key columns sorted by CA order.
This function returns key column positions in the same order as they appear in
CA’s Assembly Kit, rather than the binary order. This is primarily needed for
twad_key_deletes functionality, which uses CA’s ordering.
§Returns
Returns a vector of key column indices sorted by their ca_order value.
Sourcepub fn update_from_raw_definition(
&mut self,
raw_definition: &RawDefinition,
unfound_fields: &mut Vec<String>,
)
pub fn update_from_raw_definition( &mut self, raw_definition: &RawDefinition, unfound_fields: &mut Vec<String>, )
Updates field properties from Assembly Kit raw definition data.
This function updates the definition’s fields with data extracted from the Assembly Kit,
matching fields by name and updating specific properties. Fields not found in the
Assembly Kit are added to the unfound_fields list for reporting.
§Updated Properties
is_key: Primary key statusdefault_value: Default value for new rowsfilename_relative_path: Path hints for filename fieldsis_filename: Whether the field contains a filenameis_reference: Foreign key reference informationlookup: Lookup column informationdescription: Field descriptionca_order: Visual position in Assembly Kitis_part_of_colour: Auto-detected RGB colour field grouping
§Arguments
raw_definition- The Assembly Kit definition dataunfound_fields- List to append unfound field names to (format:"table_name/field_name")
§Note
Fields in IGNORABLE_FIELDS are automatically skipped and not reported as unfound.
§Feature
This function requires the integration_assembly_kit feature.
Sourcepub fn update_from_raw_localisable_fields(
&mut self,
raw_definition: &RawDefinition,
raw_localisable_fields: &[RawLocalisableField],
)
pub fn update_from_raw_localisable_fields( &mut self, raw_definition: &RawDefinition, raw_localisable_fields: &[RawLocalisableField], )
Populates the localised_fields list from Assembly Kit data.
This function identifies fields that should be extracted to LOC files based on
Assembly Kit localisable field data and updates the definition’s localised_fields list.
All identified localised fields are set to FieldType::StringU8 for consistency.
§Arguments
raw_definition- The Assembly Kit table definitionraw_localisable_fields- List of all localisable fields from the Assembly Kit
§Feature
This function requires the integration_assembly_kit feature.
Trait Implementations§
Source§impl Clone for Definition
impl Clone for Definition
Source§fn clone(&self) -> Definition
fn clone(&self) -> Definition
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Definition
impl Debug for Definition
Source§impl Default for Definition
impl Default for Definition
Source§fn default() -> Definition
fn default() -> Definition
Source§impl<'de> Deserialize<'de> for Definition
impl<'de> Deserialize<'de> for Definition
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<&RawDefinition> for Definition
impl From<&RawDefinition> for Definition
Source§fn from(raw_definition: &RawDefinition) -> Self
fn from(raw_definition: &RawDefinition) -> Self
Source§impl PartialEq for Definition
impl PartialEq for Definition
Source§impl Serialize for Definition
impl Serialize for Definition
impl Eq for Definition
impl StructuralPartialEq for Definition
Auto Trait Implementations§
impl Freeze for Definition
impl RefUnwindSafe for Definition
impl Send for Definition
impl Sync for Definition
impl Unpin for Definition
impl UnsafeUnpin for Definition
impl UnwindSafe for Definition
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.