thin_delegate 0.2.0

Auto implementation of trivial delegation to inner types
Documentation
// thin_delegate allows mutliple `#[thin_delegate::fill_delegate]` for a type and tratis.

#[thin_delegate::external_trait_def]
mod __external_trait_def {
    #[thin_delegate::register]
    pub trait ToString {
        /// Converts the given value to a `String`.
        ///
        /// # Examples
        ///
        /// ```
        /// let i = 5;
        /// let five = String::from("5");
        ///
        /// assert_eq!(five, i.to_string());
        /// ```
        #[rustc_conversion_suggestion]
        #[stable(feature = "rust1", since = "1.0.0")]
        #[cfg_attr(not(test), rustc_diagnostic_item = "to_string_method")]
        fn to_string(&self) -> String;
    }
}

#[thin_delegate::register]
pub trait Hello: ToString {
    fn hello(&self) -> String;
}

impl Hello for String {
    fn hello(&self) -> String {
        format!("hello, {}", &self.to_string())
    }
}

impl Hello for char {
    fn hello(&self) -> String {
        format!("hello, {}", &self.to_string())
    }
}

#[thin_delegate::register]
enum Hoge {
    A(String),
    B(char),
}

#[thin_delegate::fill_delegate(external_trait_def = __external_trait_def)]
impl ToString for Hoge {}

#[thin_delegate::fill_delegate]
impl Hello for Hoge {}

fn main() {
    let hoge = Hoge::A("a".to_string());
    assert_eq!(hoge.hello(), "hello, a");

    let hoge = Hoge::B('b');
    assert_eq!(hoge.hello(), "hello, b");
}