#literal #macro #macros #pattern #proc-macro

macro no-std expand

Macro to expand byte string and string literals

5 releases

0.2.0 Nov 6, 2020
0.1.3 Nov 3, 2020
0.1.2 Oct 25, 2020
0.1.1 Oct 24, 2020
0.1.0 Oct 23, 2020

#964 in Rust patterns

Download history 77/week @ 2022-06-03 91/week @ 2022-06-10 64/week @ 2022-06-17 136/week @ 2022-06-24 98/week @ 2022-07-01 84/week @ 2022-07-08 120/week @ 2022-07-15 124/week @ 2022-07-22 136/week @ 2022-07-29 89/week @ 2022-08-05 177/week @ 2022-08-12 114/week @ 2022-08-19 107/week @ 2022-08-26 114/week @ 2022-09-02 131/week @ 2022-09-09 65/week @ 2022-09-16

421 downloads per month
Used in mmtc

MPL-2.0 license

9KB
75 lines

expand

version dependencies license ci

Macro to expand byte string and string literals

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

~220–630KB
~15K SLoC