range-parser
About range-parser
range-parser is a simple Rust crate to parse range from text representation (e.g. 1-3,5-8
, 1,3,4
, 1-5
) into a Vector containing all the items for that range.
Get started
-
Include
range-parser
to yourCargo.toml
= "0.1"
-
Parse range from str
let range_str = "1-3,5-8"; let range: = parse.unwrap; assert_eq!;
Supported types
range-parser supports any kind of number primitive.
range-parser for custom types
It is possible to extend the range-parser for custom types as long as they satisfy these trait bounds: T: FromStr + Add<Output = T> + PartialEq + PartialOrd + Unit + Copy,
.
This requires you to implement the trait Unit
which is exposed by this library.
The trait Unit is defined as
and should return the base unit for a type, which for numbers should be 1
.
Examples
Parse a range with a dash
let range: = parse.unwrap;
assert_eq!;
Parse a range with commas
let range: = parse.unwrap;
assert_eq!;
Parse a mixed range
let range: = parse.unwrap;
assert_eq!;
Parse a range with negative numbers
let range: = parse.unwrap;
assert_eq!;
Parse a range with custom separators
// parse range using `;` as separator for values and `..` as separator for ranges
let range: = parse_with.unwrap;
assert_eq!;
Changelog
View range-parser's changelog HERE
License
range-parser is licensed under the MIT license.
You can read the entire license HERE