Skip to main content

parse_year_str

Function parse_year_str 

Source
pub fn parse_year_str(s: &str, valid_years: &[u32]) -> Result<Vec<u32>>
Expand description

Parse a string of years separated by semicolons into a vector of u32 years.

The string can be either “all” (case-insensitive) or year ranges (optionally) separated with semicolons. A year range can be a single year (e.g. 2020) or a range with a start year and/or end year (e.g. 2020.., ..2020, 2020..2025).

§Arguments

  • s - Input string to parse
  • valid_years - The possible years which can be referenced in s (must be sorted and unique)

§Returns

A Vec of years or an error.

§Panics

If valid_years is empty, unsorted or contains duplicates.