hobofan / ambassador

Delegation of trait implementations via procedural macros
Apache License 2.0
251 stars 13 forks source link

Allow to use`Delegate` with a single variant Enum #41

Closed Y-Nak closed 1 year ago

Y-Nak commented 2 years ago

Currently, it seems Delegate can't be used with a single variant Enum, which was allowed in v0.2.

Example:

use ambassador::{delegatable_trait, Delegate};

#[delegatable_trait]
pub trait Shout {
    fn shout(&self, input: &str) -> String;
}

pub struct Dog;

impl Shout for Dog {
    fn shout(&self, input: &str) -> String {
        format!("{} - wuff!", input)
    }
}

#[derive(Delegate)]
#[delegate(Shout)]
pub enum Animal {
    Dog(Dog),
}

error: no rules expected the token `body_enum`
  --> src/lib.rs:16:10
   |
3  | #[delegatable_trait]
   | -------------------- when calling this macro
...
16 | #[derive(Delegate)]
   |          ^^^^^^^^ no rules expected this token in macro call
   |
   = note: this error originates in the derive macro `Delegate` (in Nightly builds, run with -Z macro-backtrace for more info)