#macro

no-std reword

Provides a macro to generate structures used for constant value lookup

23 releases (15 stable)

✓ Uses Rust 2018 edition

5.0.0 Feb 11, 2020
4.0.1 Jan 24, 2020
4.0.0 Oct 26, 2019
3.0.2 Aug 17, 2019
0.1.4 Mar 12, 2018

#34 in No standard library

Download history 449/week @ 2019-12-07 2/week @ 2019-12-21 22/week @ 2019-12-28 2/week @ 2020-01-04 21/week @ 2020-01-11 67/week @ 2020-01-18 12/week @ 2020-01-25 3/week @ 2020-02-01 36/week @ 2020-02-08 19/week @ 2020-02-15 73/week @ 2020-02-22 23/week @ 2020-02-29 47/week @ 2020-03-07 24/week @ 2020-03-14 139/week @ 2020-03-21

227 downloads per month

MIT/Apache

7KB

reword

Travis Crates.io Docs

Provides a macro to generate structures used for value lookup.

reword::reword! {
    enum Lang: &'static str {
        fn hi {
            NO = "Hei";
            EN_UK | EN_US = "Hi";
        }

        fn fall {
            NO = "Høst";
            EN_UK = "Autumn";
            EN_US = "Fall";
        }
    }
}

let mut lang = Lang::NO;
assert_eq!(lang.hi(), "Hei");
assert_eq!(lang.fall(), "Høst");
lang = Lang::EN_UK;
assert_eq!(lang.hi(), "Hi");
assert_eq!(lang.fall(), "Autumn");
lang = Lang::EN_US;
assert_eq!(lang.hi(), "Hi");
assert_eq!(lang.fall(), "Fall");

Attributes can be attached to both the enum and the methods generated. The Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, and Hash traits are automatically derived for the enum using the derive attribute.

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