Crate macron_impl_from

Crate macron_impl_from 

Source
Expand description

githubcrates-iodocs-rs

§Impl From Macro

§Introduction:

The implementation of trait From.

P.s.: More useful macros you can find here.

§Examples:

#[derive(From, Debug, PartialEq)]
#[from(Insertion, "Self { insertion: value }")]
struct Test {
    insertion: Insertion,
}

#[derive(Debug, PartialEq)]
struct Insertion;

assert_eq!(Test { insertion: Insertion {} }, Test::from(Insertion {}));
#[derive(From, Debug, PartialEq)]
#[from(Insertion, "Self::Insertion(value)")]
enum Test {
    Insertion(Insertion),

    #[from(Insertion2, "value")]
    Insertion2(Insertion2),

    #[from(Insertion3, "insertion: value")]
    Insertion3 { insertion: Insertion3 },

    #[from]
    Insertion4(Insertion4),

    #[from]
    Insertion5 { insertion: Insertion5 },
}

#[derive(Debug, PartialEq)]
struct Insertion;

#[derive(Debug, PartialEq)]
struct Insertion2;

#[derive(Debug, PartialEq)]
struct Insertion3;

#[derive(Debug, PartialEq)]
struct Insertion4;

#[derive(Debug, PartialEq)]
struct Insertion5;

assert_eq!(Test::Insertion(Insertion {}), Test::from(Insertion {}));
assert_eq!(Test::Insertion2(Insertion2 {}), Test::from(Insertion2 {}));
assert_eq!(Test::Insertion3 { insertion: Insertion3 {} }, Test::from(Insertion3 {}));
assert_eq!(Test::Insertion4(Insertion4 {}), Test::from(Insertion4 {}));
assert_eq!(Test::Insertion5 { insertion: Insertion5 {} }, Test::from(Insertion5 {}));

§Licensing:

Distributed under the MIT license.

§Feedback:

You can contact me via GitHub or send a message to my Telegram @fuderis.

This library is constantly evolving, and I welcome your suggestions and feedback. See the documentation here macron documentation

Derive Macros§

From
The implementation of trait From