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

#56 in #string-literal

Download history 51/week @ 2023-12-18 44/week @ 2023-12-25 120/week @ 2024-01-01 132/week @ 2024-01-08 100/week @ 2024-01-15 46/week @ 2024-01-22 200/week @ 2024-01-29 169/week @ 2024-02-05 71/week @ 2024-02-12 162/week @ 2024-02-19 94/week @ 2024-02-26 97/week @ 2024-03-04 126/week @ 2024-03-11 98/week @ 2024-03-18 70/week @ 2024-03-25 202/week @ 2024-04-01

510 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

~340–800KB
~19K SLoC