3 releases
0.1.2 | Sep 5, 2020 |
---|---|
0.1.1 | Sep 5, 2020 |
0.1.0 | Sep 5, 2020 |
109 downloads per month
Used in alphabet
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