Macro create_table_match
macro_rules! create_table_match {
($table_type_var:expr, $data:expr, $rows:expr, $info:expr, $offset:expr, $(($id:path, $raw:ty, $variant:ident)),* $(,)?) => { ... };
}Expand description
Generate the complete match expression for creating metadata tables in TablesHeader::add_table().
This macro eliminates the repetitive match arm patterns that would otherwise require ~380 lines of nearly identical code. It generates a complete match expression that handles all table types, where each arm:
- Creates a
MetadataTableof the specified type - Updates the offset by the table’s size
- Wraps the table in the appropriate
TableDatavariant
§Arguments
$table_type_var- The variable containing theTableIdto match against$data- The data slice to parse from$rows- The number of rows in the table$info- TheTableInfofor column size calculation$offset- Mutable reference to the current offset$(($id:path, $raw:ty, $variant:ident)),*- List of (TableId variant, Raw type, TableData variant) tuples
§Size Calculation
The macro casts table.size() (which returns u64) to usize for offset arithmetic.
This is safe because:
- PE files are limited to ~4GB, constraining maximum metadata size
- On 64-bit systems,
usizecan hold any valid table size - On 32-bit systems, the 4GB PE limit ensures no truncation occurs
§Example
ⓘ
let table = create_table_match!(
table_type, data, t_info.rows, self.info.clone(), current_offset,
(TableId::Module, ModuleRaw, Module),
(TableId::TypeRef, TypeRefRaw, TypeRef),
// ... additional entries
);