diff options
author | dfhoughton <dfhoughton@gmail.com> | 2019-01-12 17:18:37 -0500 |
---|---|---|
committer | dfhoughton <dfhoughton@gmail.com> | 2019-01-12 17:18:37 -0500 |
commit | d3fa93c177c650edd01c0e729f2f9da86c355ee5 (patch) | |
tree | 7431bcfbe07d80b70ba87e2b44aae7748bdc436e /src/lib.rs | |
parent | a5c0ff8e41b31d0c71001a339b6099fcbc40363d (diff) | |
download | two-timer-d3fa93c177c650edd01c0e729f2f9da86c355ee5.zip |
added msg method to TimeError
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -185,7 +185,7 @@ use pidgin::{Grammar, Match, Matcher}; use regex::Regex; lazy_static! { - // making this public is useful for testing, but best to keep it hidden to + // making this public is useful for testing, but best to keep it hidden to // limit complexity and commitment #[doc(hidden)] pub static ref GRAMMAR: Grammar = grammar!{ @@ -402,6 +402,19 @@ pub enum TimeError { NoPayPeriod(String), } +impl TimeError { + /// Extracts error message. + pub fn msg(&self) -> &str { + match self { + TimeError::Parse(s) => s.as_ref(), + TimeError::Misordered(s) => s.as_ref(), + TimeError::ImpossibleDate(s) => s.as_ref(), + TimeError::Weekday(s) => s.as_ref(), + TimeError::NoPayPeriod(s) => s.as_ref(), + } + } +} + /// Converts a time expression into a pair or timestamps and a boolean indicating whether /// the expression was literally a range, such as "9 to 11", as opposed to "9 AM", say. /// |