Crate concrete_type_rules

Crate concrete_type_rules 

Source
Expand description

§Concrete Type Rules

Utilities and extensions for working with the concrete-type crate.

This crate provides additional tools for composing multiple concrete types together, including macros for generating combined matchers that can handle multiple enum types at once.

§Features

  • gen_match_concretes_macro! - Generates macros for matching multiple enum instances simultaneously, with support for 2-5 enum types.

§Examples

§Combined Matcher for Two 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>())
});

§Using With More 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);

Macros§

gen_match_concretes_macro
A macro that generates a combined matcher macro for multiple concrete enums.