#string-literal #pattern #literals #macro #proc-macro #pattern-matching

macro no-std expand

Macro to expand byte string and string literals

7 releases

0.3.0 Mar 18, 2023
0.2.1 Oct 21, 2022
0.2.0 Nov 6, 2020
0.1.3 Nov 3, 2020
0.1.2 Oct 25, 2020

#66 in #string-literal

Download history 74/week @ 2024-07-22 68/week @ 2024-07-29 61/week @ 2024-08-05 114/week @ 2024-08-12 59/week @ 2024-08-19 72/week @ 2024-08-26 65/week @ 2024-09-02 82/week @ 2024-09-09 53/week @ 2024-09-16 132/week @ 2024-09-23 101/week @ 2024-09-30 74/week @ 2024-10-07 72/week @ 2024-10-14 75/week @ 2024-10-21 98/week @ 2024-10-28 86/week @ 2024-11-04

336 downloads per month
Used in 2 crates

MPL-2.0 license

9KB
74 lines

expand

version deps license ci

Macro to expand byte string and string literals

Documentation

Usage

use expand::expand;

// expanding a byte string
assert_eq!(
    &expand!([@b"Hello,", b' ', @b"world", b'!']),
    b"Hello, world!"
);

// expanding a string
assert_eq!(
    expand!(vec![@"Hello,", ' ', @"world", '!']),
    "Hello, world!".chars().collect::<Vec<char>>(),
);

// pattern matching
if let expand!([@b"patt", x, y, b'n', ..]) = b"pattern matching" {
    assert_eq!(x, &b'e');
    assert_eq!(y, &b'r');
} else {
    panic!("pattern matching failed");
}

// more pattern matching
if let expand!([@b"msg = \"", xs @ .., b'"']) = br#"msg = "Hello, world!""# {
    assert_eq!(xs, b"Hello, world!");
} else {
    panic!("pattern matching failed");
}

Changelog

See CHANGELOG.md

Dependencies

~205–640KB
~15K SLoC