Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 5 days 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 (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-09-05T00:59:01.000Z (over 1 year ago)
- Last Synced: 2024-11-06T16:55:47.422Z (about 2 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
[![version](https://img.shields.io/crates/v/expand?logo=rust&style=flat-square)](https://crates.io/crates/expand)
[![deps](https://deps.rs/repo/github/figsoda/expand/status.svg?style=flat-square&compact=true)](https://deps.rs/repo/github/figsoda/expand)
[![license](https://img.shields.io/badge/license-MPL--2.0-blue?style=flat-square)](https://www.mozilla.org/en-US/MPL/2.0)
[![ci](https://img.shields.io/github/actions/workflow/status/figsoda/expand/ci.yml?label=ci&logo=github-actions&style=flat-square)](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)