Skip to main content

Crate fill_range

Crate fill_range 

Source
Expand description

§fill-range — fill in a range of numbers or letters

Expand a range into the sequence of values between its bounds — numbers ("1".."5" → ["1","2","3","4","5"]), letters ("a".."e" → ["a","b","c","d","e"]), with an optional step and automatic zero-padding ("01".."05" → ["01",…,"05"]). A faithful Rust port of the fill-range npm package. Zero dependencies and #![no_std].

use fill_range::{fill, fill_step};

assert_eq!(fill("1", "5"), ["1", "2", "3", "4", "5"]);
assert_eq!(fill("a", "e"), ["a", "b", "c", "d", "e"]);
assert_eq!(fill("01", "05"), ["01", "02", "03", "04", "05"]); // auto-padded
assert_eq!(fill("5", "1"), ["5", "4", "3", "2", "1"]);        // descending
assert_eq!(fill_step("0", "10", 2), ["0", "2", "4", "6", "8", "10"]);

To build a regex that matches a numeric range (the toRegex option of the npm package), compose with the to-regex-range crate.

Functions§

fill
Fill in the range from start to end (inclusive) with a step of 1.
fill_step
Fill in the range from start to end (inclusive) with the given step.