#str #const #proc-macro #macro #string

macro proc_strarray

Create const u8 array from str literal

3 stable releases

new 1.2.0 Nov 23, 2024
1.1.0 Jul 31, 2024
1.0.0 Jul 29, 2024

#461 in Procedural macros

Download history 6/week @ 2024-08-04 28/week @ 2024-09-15 9/week @ 2024-09-22 1/week @ 2024-09-29 85/week @ 2024-11-17

87 downloads per month

MIT/Apache

18KB
247 lines

Procedural macros for str literals

MIT OR Apache License Crates.io Version MSRV 1.57 Safe Rust Documentation Crates.io Downloads

Create array from str

Procedural macro proc_strarray::make_array creates const u8 array from str literal. Variant proc_strarray::make_array0 creates zero terminated u8 array.

Macro make_array takes three arguments:

  1. name of array to be created
  2. str literal
  3. expected length of str literal (optional argument, can be omitted)

Repeat str

  1. macro str_repeat repeats str literal n times.
  2. macro str_repeat0 repeats str literal n times and adds zero termination.

Return str length

  1. macro str_len returns length of str literal.
  2. macro str_len0 returns length of zero terminated str literal.

Usage

    // This code will create const array of u8
    // named STRU from content of "stru" str literal.
    use proc_strarray::make_array;
    make_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 and MSRV

proc_strarray uses same license as Rust. MSRV is 1.57 and it will stay for all 1.X versions.

Dependencies

~1.5MB
~42K SLoC