Function range_parser::parse_with

source ·
pub fn parse_with<T>(
    range_str: &str,
    value_separator: &str,
    range_separator: &str,
) -> RangeResult<Vec<T>>
where T: FromStr + Add<Output = T> + PartialEq + PartialOrd + Unit + Copy,
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: char - the separator for single values
  • range_separator: char - the separator for ranges

§Returns

  • Result<Vec, RangeError> - the parsed range

§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]);