| Crates.io | bexpand |
| lib.rs | bexpand |
| version | 1.3.1-alpha.1 |
| created_at | 2023-06-24 22:29:59.35542+00 |
| updated_at | 2025-04-30 06:02:38.689856+00 |
| description | Bash-style brace expansion |
| homepage | |
| repository | https://forge.axfive.net/Taylor/bexpand |
| max_upload_size | |
| id | 899148 |
| size | 54,106 |
Bash-style brace expansion in Rust.
Documentation on docs.rs as usual
The main entrypoint is bexpand::Expression, using either TryFrom<&str> or FromStr.
use bexpand::Expression;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let expression: Expression = "expression: {foo,bar,baz}".try_into()?;
for generated in expression {
println!("each: {}", generated?);
}
Ok(())
}
abcd\ to be considered as regular characters: ab\{cd
{}\.,{}\.,.{}\.\ will be taken literally, even if it's redundant.
\n, for example, represents n, not a newline character.{a,b,c}, {a,,c}, {}, {,}
{<spec><start>..<end>[..<stride>]}
<spec> is a possibly-empty set of format specifier characters:
= means to expand each item with leading zeroes to the width of the
longest character width of <start> and <end>.<start> and <end> are signed 64-bit integers. If <end> is less than
<start>, the sequence will count downwards.<stride> is an optional non-negative increment number, to count by
increments of more than 1.
<stride> is 1.<stride> is always normalized to 1 to prevent infinite looping.'{9223372036854775806..9223372036854775807..1000}' just produces
9223372036854775806, not an error.{<start>..<end>[..<stride>]}
<start> and <end> are unicode characters to produce codepoints for
in order. If <end> is less than <start>, the sequence will cycle
downwards. If this range would end up producing a surrogate codepoint, an
error is given for each instead.
<stride> is an optional non-negative increment number, to count by
increments of more than 1.
<stride> is 1.<stride> is always normalized to 1 to prevent infinite looping.'{a..z..1114111}' just produces a, not an error{a,b}c{d,e}f{g..i} produces
["acdfg","acdfh","acdfi","acefg","acefh","acefi","bcdfg","bcdfh","bcdfi","bcefg","bcefh","bcefi"]'{a,{b,,c{\,..\.}}{f..d..2}}' produces ["a","bf","bd","f","d","c,f","c,d","c-f","c-d","c.f","c.d"]This does not 100% conform to Bash's style in the following ways:
a{b,c}d}e expands to
abd}e acd}e and a{b{c,d}e expands to a{bce a{bde. In bexpand, both are
errors.a{}b and a{b}c are both literally repeated by the shell. In
bexpand, these expand to ab and abc.{🥰..🥴..2} is a valid character sequence, as is {\{..\.}, and {9..A}.
Technically, {\0..\9} is valid as well, and will be treated as a character
sequence, though it expands to the exact same thing as a numeric sequence of
the same form. Anything that would generate an illegal unicode codepoint will
generate an error.{001..100} is instead done in bexpand as
{=1..100}. This is to allow things like {=-5..10}, which is impossible to
express in Bash.Copyright 2023-2025 Taylor Richberger
Published under the terms of the Mozilla Public License Version 2.0.