8 releases

0.4.0 May 15, 2023
0.3.3 Oct 6, 2020
0.3.2 Sep 30, 2020
0.3.0 Jul 16, 2020
0.1.1 May 7, 2019

#447 in Procedural macros

Download history 3226/week @ 2024-08-14 2706/week @ 2024-08-21 2338/week @ 2024-08-28 2003/week @ 2024-09-04 2605/week @ 2024-09-11 2924/week @ 2024-09-18 2919/week @ 2024-09-25 2261/week @ 2024-10-02 2043/week @ 2024-10-09 2748/week @ 2024-10-16 2800/week @ 2024-10-23 2225/week @ 2024-10-30 3459/week @ 2024-11-06 3447/week @ 2024-11-13 3528/week @ 2024-11-20 2862/week @ 2024-11-27

13,659 downloads per month
Used in 35 crates (15 directly)

MIT license

9KB
168 lines

Casey

Build

Case transforming macros

Casey transforms the case of given input idents.
Niche but maybe useful in other macros.

use casey::{pascal, lower, shouty, snake, upper};

lower!(ABC);    // renders: `abc`
upper!(abc);    // `ABC`
snake!(ABC);    // `a_b_c`
pascal!(ab_c);  // `AbC`
shouty!(a_b_c); // `A_B_C`

Token Stream

Casey macros can operate on TokenStreams e.g.

    snake!(
        #[derive(PartialEq)]
        struct MockStruct {}
        impl MockStruct {
            fn test() -> bool { true }
        }
    );
    assert!(mock_struct::test());
    assert!(mock_struct::test() == mock_struct::test())

All ident tokens in the stream will have the case transformation applied (keywords and attribute macros will be ignored).

Gotchas

Type names, including built-in types are not considered keywords e.g. bool, usize, i32 etc. and will be transformed by casey.

pascal!(let test: bool = true); // renders: `let Test: Bool = true;`

Dependencies

~1.5MB
~37K SLoC