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 (the
expander behind minimatch/glob), which implements bash's rules. Zero
dependencies and #![no_std].
use expand;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!; // zero-padded
assert_eq!; // step
assert_eq!; // 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.
[]
= "0.1"
API
| Item | Purpose |
|---|---|
expand(pattern) |
Expand a pattern into a Vec<String> |
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 specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the 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 or MIT at your option.