concrete-type-rules

Crates.ioconcrete-type-rules
lib.rsconcrete-type-rules
version
sourcesrc
created_at2025-04-13 14:56:59.970812+00
updated_at2025-04-13 14:58:04.654441+00
descriptionRules and validation for concrete types
homepage
repositoryhttps://github.com/justastream/concrete-type
max_upload_size
id1631873
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Just A Stream (just-a-stream)

documentation

https://docs.rs/concrete-type-rules

README

concrete-type-rules

Crates.io Documentation MIT License

Utilities and extensions for working with the concrete-type crate, providing macros for composing multiple concrete enum types.

Table of Contents

Overview

concrete-type-rules extends the functionality of the concrete-type crate by providing utilities for working with multiple concrete enum types simultaneously. This enables:

  • Composing multiple enum types together through generated macros
  • Reducing nesting and improving code readability
  • Creating type-safe interfaces for generic components
  • Supporting up to 5 enum types in a single match expression

Installation

Add this to your Cargo.toml:

[dependencies]
concrete-type = "0.2.0"
concrete-type-rules = "0.1.0"

Features

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.

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

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);

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

Commit count: 0

cargo fmt