concrete-type
A procedural macro library for mapping enum variants to concrete types, enabling type-level programming based on runtime enum values.
Table of Contents
Overview
concrete-type provides procedural macros that create a relationship between enum variants and specific concrete types.
This enables:
- Type-level programming with enums
- Executing code with concrete type knowledge at compile time based on runtime enum values
- Optionally carrying configuration data with enum variants
Installation
Add this to your Cargo.toml:
[]
= "0.2.0"
Features
#[derive(Concrete)]
The Concrete derive macro is designed for enums where each variant maps to a specific concrete type.
- Map enum variants to concrete types with
#[concrete = "path::to::Type"]attribute - Auto-generated macros for type-level dispatch using the snake_case name of the enum
Example:
// Generated macro is named 'strategy_kind!'
#[derive(ConcreteConfig)]
The ConcreteConfig derive macro is designed for enums where each variant has associated configuration data and maps to a specific concrete type.
- Map enum variants with configuration data to concrete types
- Each variant must have a single tuple field containing the configuration
- Generated methods:
config(): Returns a reference to the configuration data
- Auto-generated macros for type-level dispatch with access to both the concrete type and config data
Example:
// Generated macro is named 'exchange_config!'
Examples
Basic Usage
use Concrete;
// Use the auto-generated 'exchange!' macro to work with concrete types
let exchange = Binance;
let name = exchange!;
assert_eq!;
Enums with Config Data
use ConcreteConfig;
// Define concrete types and configuration types
// Define the enum with concrete type mappings and config data
// Using the auto-generated macro with access to both type and config
let config = Binance;
let name = exchange_config!;
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT