Skip to main content

Crate disponent

Crate disponent 

Source
Expand description

§disponent

An alternative to dyn Trait for dispatching to multiple implementations.

§Example

Use the declare! macro to define a trait and enum together. The enum will implement the trait by delegating method calls to its variants.

use disponent::declare;

declare!(
    pub enum FooOrBar {
        Foo(Foo),
        Bar(Bar),
    }

    pub trait SayHello {
        fn say_hello(&self);
    }
);

§Configuration

Use #[disponent::configure(...)] on the enum with:

  • inherent: Generate inherent methods (vs trait impl)
  • inline: Add #[inline] to methods
  • from: Generate From<T> for Enum impls
  • try_into: Generate TryInto<T> for Enum impls

§Remote Traits

Use #[disponent::remote(...)] on the trait to implement a trait defined elsewhere.

Macros§

declare
Declare a trait and enum together, generating forwarding methods.

Attribute Macros§

configure
Configure the enum forwarding behavior.
remote
Use a remote trait instead of the declared trait.