#enum #macro #static

no-std enum_properties

A macro for declaring static properties on enum variants

4 releases (2 breaking)

0.3.0 May 19, 2021
0.2.1 Mar 31, 2020
0.2.0 Mar 31, 2020
0.1.0 Mar 6, 2020

#378 in Rust patterns

Download history 715/week @ 2021-07-04 709/week @ 2021-07-11 759/week @ 2021-07-18 566/week @ 2021-07-25 703/week @ 2021-08-01 63/week @ 2021-08-08 608/week @ 2021-08-15 509/week @ 2021-08-22 287/week @ 2021-08-29 371/week @ 2021-09-05 383/week @ 2021-09-12 374/week @ 2021-09-19 212/week @ 2021-09-26 248/week @ 2021-10-03 189/week @ 2021-10-10 732/week @ 2021-10-17

79 downloads per month
Used in 5 crates (via taml)

Apache-2.0

10KB
101 lines

enum_properties

Documentation

A macro for declaring static properties on enum variants. See the documentation for more information.

Example

use enum_properties::enum_properties;

struct SolidProperties {
    verts: i32,
    edges: i32,
    faces: i32,
}

enum_properties! {
    #[derive(Clone, Copy, Debug)]
    enum PlatonicSolid: SolidProperties {
        Tetrahedron {
            verts: 4,
            edges: 6,
            faces: 4,
        },
        Cube {
            verts: 8,
            edges: 12,
            faces: 6,
        },
        Octahedron {
            verts: 6,
            edges: 12,
            faces: 8,
        },
        Dodecahedron {
            verts: 20,
            edges: 30,
            faces: 12,
        },
        Icosahedron {
            verts: 12,
            edges: 30,
            faces: 20,
        },
    }
}

fn main() {
    let cube = PlatonicSolid::Cube;
    assert_eq!(cube.verts - cube.edges + cube.faces, 2);
}

No runtime deps