Crates.io | expand |
lib.rs | expand |
version | 0.3.0 |
source | src |
created_at | 2020-10-23 16:31:48.258163 |
updated_at | 2023-03-18 20:53:31.816105 |
description | Macro to expand byte string and string literals |
homepage | https://github.com/figsoda/expand |
repository | https://github.com/figsoda/expand |
max_upload_size | |
id | 304731 |
size | 27,207 |
Macro to expand byte string and string literals
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");
}
See CHANGELOG.md