trait-mux
Proc macro library for generating enums that can multiplex different trait objects.
Overview
trait-mux
provides a macro solution for multiplexing different trait objects within a single enum. This is useful when you need to handle multiple trait implementations through a common interface.
Installation
Add this to your Cargo.toml
:
[]
= "0.3.2"
Usage
Basic Example
use trait_mux;
// Define some traits
// Generate a multiplexer enum for these traits
trait_mux!;
// Implement traits for concrete types
;
;
;
;
Features
- Generate enums that wrap multiple trait objects
- Automatic conversion from implementors to the generated enum
- Type-safe downcasting back to specific trait objects
- Support for generic traits
How It Works
The #[trait_mux]
attribute macro generates an enum with variants for each possible combination of
the specified traits. It also implements conversion methods, allowing you to:
- Convert trait implementors to the enum
- Downcast from the enum back to trait objects
- Access trait methods in a type-safe manner
License
This project is licensed under the MIT License.