| Crates.io | concrete-type-rules |
| lib.rs | concrete-type-rules |
| version | 0.1.1 |
| created_at | 2025-04-13 14:56:59.970812+00 |
| updated_at | 2025-04-13 14:58:04.654441+00 |
| description | Rules and validation for concrete types |
| homepage | |
| repository | https://github.com/justastream/concrete-type |
| max_upload_size | |
| id | 1631873 |
| size | 22,195 |
Utilities and extensions for working with the concrete-type crate, providing macros for composing multiple concrete enum types.
concrete-type-rules extends the functionality of the concrete-type crate by providing utilities for working with multiple concrete enum types simultaneously. This enables:
Add this to your Cargo.toml:
[dependencies]
concrete-type = "0.2.0"
concrete-type-rules = "0.1.0"
gen_match_concretes_macro!The gen_match_concretes_macro! macro generates a new macro that allows you to match multiple enum instances simultaneously, providing type parameters for each concrete type associated with the enum variants.
Supports from 2 to 5 enum types.
use concrete_type::Concrete;
use concrete_type_rules::gen_match_concretes_macro;
#[derive(Concrete)]
enum Exchange {
#[concrete = "exchanges::Binance"]
Binance,
}
#[derive(Concrete)]
enum Strategy {
#[concrete = "strategies::StrategyA"]
StrategyA,
}
mod exchanges {
pub struct Binance;
}
mod strategies {
pub struct StrategyA;
}
// Generate a combined matcher macro
gen_match_concretes_macro!(Exchange, Strategy);
// Now you can use the generated macro with both enum instances
let exchange = Exchange::Binance;
let strategy = Strategy::StrategyA;
// This uses a single match expression for both enums
let result = match_exchange_strategy!(exchange, strategy; E, S => {
// E is exchanges::Binance, S is strategies::StrategyA
format!("{} + {}", std::any::type_name::<E>(), std::any::type_name::<S>())
});
The macro supports up to 5 enum types:
// For 3 enum types:
gen_match_concretes_macro!(Exchange, Strategy, Market);
// Generated macro name combines all enum names in snake_case
// E.g., match_exchange_strategy_market!
// For 4 or 5 enum types:
gen_match_concretes_macro!(Exchange, Strategy, Market, Asset, TimeFrame);
Contributions are welcome! Please feel free to submit a Pull Request.
MIT