#alphabet #macro #helper #language #formal-language

macro alphabet-macro

Provides a macro that can be used to easily create const alphabets

3 releases

0.1.2 Sep 5, 2020
0.1.1 Sep 5, 2020
0.1.0 Sep 5, 2020

#44 in #alphabet

Download history 24/week @ 2024-02-18 11/week @ 2024-02-25 11/week @ 2024-03-03 13/week @ 2024-03-10 5/week @ 2024-03-17 10/week @ 2024-03-24 25/week @ 2024-03-31

55 downloads per month
Used in alphabet

MIT license

7KB
57 lines

alphabet-macro

A Rust crate for easy alphabet creation. Documentation is available on docs.rs.

Usage

Add this to your Cargo.toml:

[dependencies]
alphabet-macro = "0.1"

Getting Started

use alphabet_macro::alphabet;

alphabet!(HEX = "0123456789abcdef");

assert_eq!(HEX.len(), 16);
assert_eq!(HEX[5], '5');
assert_eq!(HEX[10], 'a');

License

This crate is published under the terms of the MIT license. See the LICENSE file for details.


lib.rs:

Provides the alphabet!() macro. It can be used to create const alphabets easily.

Usually you would have to write alphabets in a cumbersome way:

const HEX: [char; 16] = ['0', '1', '2', '3',
    '4', '5', '6', '7',
    '8', '9', 'a', 'b',
    'c', 'd', 'e', 'f'];

assert_eq!(HEX.len(), 16);
assert_eq!(HEX[5], '5');
assert_eq!(HEX[10], 'a');

But with the alphabet!() macro this can be done way easier.

use alphabet_macro::alphabet;

alphabet!(HEX = "0123456789abcdef");

assert_eq!(HEX.len(), 16);
assert_eq!(HEX[5], '5');
assert_eq!(HEX[10], 'a');

The alphabet!() macro expands to the snippet above, while being easier to read, write and understand.

Dependencies

~1.5MB
~34K SLoC