https://github.com/figsoda/expand
Rust library that introduces a macro to expand byte string and string literals
https://github.com/figsoda/expand
byte-string bytestring hacktoberfest macro macros pattern patterns proc-macro rust string
Last synced: about 2 months ago
JSON representation
Rust library that introduces a macro to expand byte string and string literals
- Host: GitHub
- URL: https://github.com/figsoda/expand
- Owner: figsoda
- License: mpl-2.0
- Created: 2020-10-23T14:12:12.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-09-05T00:59:01.000Z (over 1 year ago)
- Last Synced: 2025-03-10T19:06:47.536Z (3 months ago)
- Topics: byte-string, bytestring, hacktoberfest, macro, macros, pattern, patterns, proc-macro, rust, string
- Language: Rust
- Homepage: https://docs.rs/expand
- Size: 47.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# expand
[](https://crates.io/crates/expand)
[](https://deps.rs/repo/github/figsoda/expand)
[](https://www.mozilla.org/en-US/MPL/2.0)
[](https://github.com/figsoda/expand/actions?query=workflow:ci)Macro to expand byte string and string literals
[Documentation](https://docs.rs/expand)
## Usage
```rust
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::>(),
);// 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](CHANGELOG.md)