10 stable releases
| 1.7.0 | May 30, 2025 |
|---|---|
| 1.6.0 | Dec 1, 2024 |
| 1.5.1 | Nov 29, 2024 |
| 1.1.0 | Jul 31, 2024 |
#2740 in Procedural macros
611 downloads per month
Used in fnv0
32KB
514 lines
Procedural macros for str and byte str literals
Create byte array from str or byte str
Procedural macro proc_strarray::str_array creates const u8 array from str literal.
Variant proc_strarray::str_array0 creates zero terminated u8 array.
Macro str_array takes three arguments:
- name of array to be created
- str or byte str literal
- expected length of str literal (optional argument, can be omitted). Length is only used for length check. It will not trim or extend an array.
Repeat str or byte str
- macro
str_repeatrepeats str or byte str literal n times. - macro
str_repeat0repeats str or byte str literal n times and adds NUL termination.
Repeat str or byte str as bytes
- macro
str_repeat_bytesrepeats str or byte str literal n times as byte slice. - macro
str_repeat_bytes0repeats str or byte str literal n times as byte slice and adds NUL termination.
Return str or byte str length
- macro
str_lenreturns length of str or byte str literal. - macro
str_len0returns length of zero terminated str or byte str literal.
Create byte slice from str or byte str
- macro
str_bytescreates byte slice from str or byte str literal. - macro
str_bytes0creates zero terminated byte slice from str or byte str literal.
Usage
// This code will create const array of u8
// named STRU from content of "stru" str literal.
use proc_strarray::str_array;
str_array!(STRU, "stru");
// check if newly created array have length 4
assert_eq!(STRU.len(), 4);
// check created array if first character is 's'
assert_eq!(STRU[0], 's' as u8);
Documentation
rustdoc generated documentation can be found at docs.rs
License
proc_strarray uses same MIT/APL2 dual license as Rust.
MSRV
MSRV 1.56 and it will stay for all 1.X versions.
Dependencies
~2MB
~44K SLoC