expand

Macro to expand byte string and string literals


Keywords
literal, pattern, proc-macro, macro, macros, byte-string, bytestring, hacktoberfest, patterns, rust, string
License
MPL-2.0

Documentation

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