Macro dispatch_table_type

macro_rules! dispatch_table_type {
    ($table_id:expr, |$RawType:ident| $expr:expr) => { ... };
}
Expand description

Macro that provides unified dispatch from TableId enum values to their corresponding Raw table types.

This macro eliminates code duplication across the framework by providing a single source of truth for TableId → Raw type mapping. It takes an expression that will be applied to each Raw type, enabling generic operations across all metadata table types.

§Usage Examples

For table row size calculation:

use crate::metadata::tables::dispatch_table_type;
dispatch_table_type!(table_id, |RawType| RawType::row_size(table_info))

For table writing operations:

use crate::metadata::tables::dispatch_table_type;
dispatch_table_type!(table_id, |RawType| {
    if let Some(table) = self.tables_header.table::<RawType>() {
        self.write_typed_table(table, table_offset)
    } else {
        Ok(0)
    }
})

For generic table operations:

use crate::metadata::tables::dispatch_table_type;
dispatch_table_type!(table_id, |RawType| {
    // Any operation that needs to work with the concrete Raw type
    process_table::<RawType>(context)
})

§Design Pattern

This macro implements the “dispatch to concrete type” pattern, allowing code to:

  1. Accept a runtime TableId value
  2. Map it to the corresponding compile-time *Raw type
  3. Execute type-specific operations with full type safety
  4. Avoid large match statements and code duplication

The pattern is essential for metadata operations that need to work generically across all table types while maintaining type safety and performance.

§Framework Usage

This macro is successfully used throughout the framework for:

  • Table row size calculations during binary generation
  • Table writing operations during assembly serialization
  • Any scenario requiring TableId → Raw type dispatch with uniform operations