https://github.com/trananhtung/brace-expansion
Bash-style brace expansion: a{b,c}d -> [abd, acd], {1..3} -> [1,2,3]. A faithful Rust port of the brace-expansion npm package. Zero deps, no_std.
https://github.com/trananhtung/brace-expansion
bash brace-expansion glob no-std rust
Last synced: 7 days ago
JSON representation
Bash-style brace expansion: a{b,c}d -> [abd, acd], {1..3} -> [1,2,3]. A faithful Rust port of the brace-expansion npm package. Zero deps, no_std.
- Host: GitHub
- URL: https://github.com/trananhtung/brace-expansion
- Owner: trananhtung
- License: apache-2.0
- Created: 2026-06-22T07:16:59.000Z (10 days ago)
- Default Branch: master
- Last Pushed: 2026-06-22T14:45:05.000Z (10 days ago)
- Last Synced: 2026-06-22T16:16:38.187Z (10 days ago)
- Topics: bash, brace-expansion, glob, no-std, rust
- Language: Rust
- Size: 15.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# brace-expansion
[](#contributors-)
[](https://crates.io/crates/brace-expansion)
[](https://docs.rs/brace-expansion)
[](https://github.com/trananhtung/brace-expansion/actions/workflows/ci.yml)
[](#license)
**Bash-style brace expansion** — `a{b,c}d` → `["abd", "acd"]`, `{1..3}` →
`["1", "2", "3"]`. A faithful Rust port of the
[`brace-expansion`](https://www.npmjs.com/package/brace-expansion) npm package (the
expander behind `minimatch`/`glob`), which implements `bash`'s rules. Zero
dependencies and `#![no_std]`.
```rust
use brace_expansion::expand;
assert_eq!(expand("a{b,c}d"), ["abd", "acd"]);
assert_eq!(expand("{1..3}"), ["1", "2", "3"]);
assert_eq!(expand("{a..c}"), ["a", "b", "c"]);
assert_eq!(expand("{01..03}"), ["01", "02", "03"]); // zero-padded
assert_eq!(expand("{1..10..2}"), ["1", "3", "5", "7", "9"]); // step
assert_eq!(expand("a{b,c{d,e}}f"), ["abf", "acdf", "acef"]); // nested
```
## Why brace-expansion?
Brace expansion is the first thing a shell does to a glob, and the JS module that
implements it is one of the most-depended-on packages in existence. Its rules are
deceptively subtle — numeric and alphabetic sequences, optional steps and
zero-padding, nested sets, backslash escaping, and a handful of bash compatibility
quirks. This is that algorithm, ported faithfully: output is identical to the npm
package (verified over thousands of patterns), which in turn matches `bash` for
ordinary patterns.
```toml
[dependencies]
brace-expansion = "0.1"
```
## API
| Item | Purpose |
| --- | --- |
| `expand(pattern)` | Expand a pattern into a `Vec` |
| `expand_with_max(pattern, max)` | Same, with a custom result cap |
| `EXPANSION_MAX` | The default cap (`100_000`) |
## Behavior
- Comma sets (`{a,b,c}`) expand to each member; sets combine as a cross product.
- `{x..y}` is a sequence: numeric (`{1..5}`, `{-3..3}`) or alphabetic (`{a..e}`),
with an optional step (`{0..10..2}`) and zero-padding (`{01..05}`).
- Sets and sequences nest arbitrarily.
- `\{`, `\}`, `\,`, `\.`, and `\\` are escaped and emitted literally.
- Patterns with no valid expansion (`foo`, `{a}`, `a{}b`) are returned unchanged,
including bash's leading-`{}` quirk.
Output is identical to the npm package for ordinary patterns (verified over many
thousands of cases). A few deliberate edge differences: sequence endpoints use exact
`i64` arithmetic rather than JavaScript's lossy `f64` (so they stay exact past 2^53),
nesting beyond a few hundred levels degrades gracefully instead of recursing without
bound, and the literal NUL-delimited markers used internally are not expected in
real patterns.
## Contributors ✨
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the [emoji key](https://allcontributors.org/docs/en/emoji-key) for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
## License
Licensed under either of [Apache-2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT) at
your option.