#macro

no-std reword

Provides a macro to generate structures used for constant value lookup

20 releases (12 stable)

✓ Uses Rust 2018 edition

new 3.0.2 Aug 17, 2019
3.0.0 May 29, 2019
2.0.0 Mar 29, 2019
1.0.7 Mar 27, 2019
0.1.4 Mar 12, 2018

#21 in No standard library

Download history 18/week @ 2019-05-04 18/week @ 2019-05-11 21/week @ 2019-05-18 82/week @ 2019-05-25 23/week @ 2019-06-01 109/week @ 2019-06-08 13/week @ 2019-06-15 157/week @ 2019-06-22 55/week @ 2019-06-29 91/week @ 2019-07-06 18/week @ 2019-07-20 26/week @ 2019-08-03 33/week @ 2019-08-10

210 downloads per month

MIT/Apache

8KB
60 lines

reword

Travis Crates.io Docs

Provides a macro to generate structures used for constant value lookup.

reword! {
    enum Lang: &'static str {
        struct Hi {
            const NO = "Hei";
            const EN_UK | EN_US = "Hi";
        }
        struct Humor {
            const NO | EN_US = "Humor";
            const EN_UK = "Humour";
        }
    }
}

let mut lang = Lang::NO;
assert_eq!(lang.get::<Hi>(), "Hei");
assert_eq!(lang.get::<Humor>(), "Humor");
lang = Lang::EN_UK;
assert_eq!(lang.get::<Hi>(), "Hi");
assert_eq!(lang.get::<Humor>(), "Humour");
lang = Lang::EN_US;
assert_eq!(lang.get::<Hi>(), "Hi");
assert_eq!(lang.get::<Humor>(), "Humor");

The structures generated are not exported out of its module by default. Use pub before theenum keyword to export it. Attributes can be attached to both the enum and the structures generated. The Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, and Hash traits are automatically derived for the types using the derive attribute. At the moment, the macro can only be used once per module, so if you need to define multiple structures you should put them in separate submodules.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps