#proc-macro #macro-derive #proc

macro macron-impl-from

The implementation of trait From

2 releases

0.1.1 May 25, 2025
0.1.0 Apr 6, 2025

#34 in #proc

Download history 7/week @ 2025-06-12 24/week @ 2025-06-19 11/week @ 2025-06-26 11/week @ 2025-07-03 27/week @ 2025-07-10 28/week @ 2025-07-17 53/week @ 2025-07-24 21/week @ 2025-07-31 34/week @ 2025-08-07 17/week @ 2025-08-14 38/week @ 2025-08-21 31/week @ 2025-08-28 49/week @ 2025-09-04 33/week @ 2025-09-11 30/week @ 2025-09-18 34/week @ 2025-09-25

150 downloads per month
Used in 5 crates (via macron)

MIT license

9KB
100 lines

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.

Dependencies

~170–580KB
~14K SLoC