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
Download history 16/week @ 2024-07-22 13/week @ 2024-07-29 8/week @ 2024-08-05 14/week @ 2024-08-12 5/week @ 2024-08-19 29/week @ 2024-08-26 7/week @ 2024-09-02 12/week @ 2024-09-09 4/week @ 2024-09-16 31/week @ 2024-09-23 14/week @ 2024-09-30 14/week @ 2024-10-14 3/week @ 2024-10-21 43/week @ 2024-10-28 49/week @ 2024-11-04

109 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
~37K SLoC