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

macro proc_strarray

Create const u8 array from str literal

2 stable releases

1.1.0 Jul 31, 2024
1.0.0 Jul 29, 2024

#532 in Procedural macros

Download history 233/week @ 2024-07-26 32/week @ 2024-08-02

60 downloads per month

MIT/Apache

12KB
164 lines

Procedural macros for str literals

Convert str to const [ u8; _ ] array

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

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

Repeat str

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

Misc functions

  1. Utility function str_len returns length of 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);

Dependencies

~2MB
~43K SLoC