4 releases

new 0.0.4 Jul 21, 2024
0.0.3 Jul 21, 2024
0.0.2 May 18, 2024
0.0.1 Jan 14, 2023

#1889 in Procedural macros

Download history 8/week @ 2024-04-04 3/week @ 2024-04-11 2/week @ 2024-05-09 197/week @ 2024-05-16 17/week @ 2024-05-23 9/week @ 2024-05-30 2/week @ 2024-06-06 1/week @ 2024-06-13 1/week @ 2024-06-27 6/week @ 2024-07-04 174/week @ 2024-07-18

181 downloads per month
Used in 2 crates (via good-ormning)

ISC license

10KB
206 lines

Derives an enum of same-variant pairs of another enum.

Installation

cargo add samevariant

Use

Define an enum and use this derive macro:

#[samevariant(pub ABCSameVariant)]
pub enum ABC {
    A,
    B,
    C(i32),
}

It generates a new enum that looks like:

enum ABCSameVariant<'l> {
    Nonmatching(&'l ABC, &'l ABC),
    A,
    B,
    C(&'l i32, &'l i32),
}

impl ABCSameVariant {
    fn pairs<'l>(a: &'l ABC, b: &'l ABC) -> ABCSameVariant<'l> {
        ...
    }
}

If the base enum has a variant Nonmatching it will be prefixed by the original enum name (like ABCNonmatching).

Only simple and tuple variants are supported, struct-like variants will result in an error.

Dependencies

~10–24MB
~316K SLoC