Function parse

Source
pub fn parse<T>(range_str: &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 number

The type T must implement the FromStr, Add, PartialEq, PartialOrd, Unit and Copy traits.

§Arguments

  • range_str: &str - the range string to parse

§Returns

  • Result<Vec, RangeError> - the parsed range

§Example

let range: Vec<u64> = range_parser::parse::<u64>("0-3").unwrap();
assert_eq!(range, vec![0, 1, 2, 3]);

let range: Vec<u64> = range_parser::parse::<u64>("0,1,2,3").unwrap();
assert_eq!(range, vec![0, 1, 2, 3]);

let range: Vec<i32> = range_parser::parse::<i32>("0,3,5-8,-1").unwrap();
assert_eq!(range, vec![0, 3, 5, 6, 7, 8, -1]);