pub fn parse_with<T>(
range_str: &str,
value_separator: &str,
range_separator: &str,
) -> RangeResult<Vec<T>>
Expand description
Parse a range string to a vector of any kind of numbers with custom separators
The type T must implement the FromStr
, Add
, PartialEq
, PartialOrd
, Unit
and Copy
traits.
§Arguments
- range_str: &str - the range string to parse
- value_separator: &str - the separator for single values
- range_separator: &str - the separator for ranges
§Returns
- Result<Vec
, RangeError> - the parsed range
§Ambiguous separators
The range separator cannot be the same as the value separator, and it cannot be one of the following: --
,
because it’s ambiguous since it couldn’t resolve negative numbers.
§Example
let range: Vec<i32> = range_parser::parse_with::<i32>("0;3;5..8;-1", ";", "..").unwrap();
assert_eq!(range, vec![0, 3, 5, 6, 7, 8, -1]);