summaryrefslogtreecommitdiff
path: root/src/parse_options.rs
diff options
context:
space:
mode:
authorFredrik Meringdal <fmeringdal@hotmail.com>2020-10-27 21:35:30 +0100
committerFredrik Meringdal <fmeringdal@hotmail.com>2020-10-27 21:35:30 +0100
commitcc3cd851849b01e30c5d43e072eea376fe6596e5 (patch)
treea1564616b879e8daa72a46d79ef58f2cef044421 /src/parse_options.rs
parent0e892cdc0415477b783af1e732fffd1a4444ce3a (diff)
downloadrust_rrule-cc3cd851849b01e30c5d43e072eea376fe6596e5.zip
Yeeah, better error handling and tests passing
Diffstat (limited to 'src/parse_options.rs')
-rw-r--r--src/parse_options.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/parse_options.rs b/src/parse_options.rs
index 49b7550..e360762 100644
--- a/src/parse_options.rs
+++ b/src/parse_options.rs
@@ -1,9 +1,9 @@
use chrono::prelude::*;
-use crate::options::{ParsedOptions, Frequenzy, Options};
+use crate::options::{ParsedOptions, Frequenzy, Options, RRuleParseError};
use chrono_tz::{Tz, UTC};
// TODO: Validation
-pub fn parse_options(options: &Options) -> ParsedOptions {
+pub fn parse_options(options: &Options) -> Result<ParsedOptions, RRuleParseError> {
let mut default_partial_options = Options::new();
default_partial_options.interval = Some(1);
default_partial_options.freq = Some(Frequenzy::Yearly);
@@ -23,7 +23,7 @@ pub fn parse_options(options: &Options) -> ParsedOptions {
let freq = partial_options.freq.unwrap();
if partial_options.dtstart.is_none() {
- panic!("Dtstart can not be None");
+ return Err(RRuleParseError(String::from("Dtstart can not be None")));
}
if partial_options.wkst.is_none() {
@@ -33,7 +33,7 @@ pub fn parse_options(options: &Options) -> ParsedOptions {
if let Some(bysetpos) = &partial_options.bysetpos {
for pos in bysetpos {
if *pos == 0 || !(*pos >= -366 && *pos <= 366) {
- panic!("bysetpos must be between 1 and 366, or between -366 and -1");
+ return Err(RRuleParseError(String::from("Bysetpos must be between 1 and 366, or between -366 and -1")));
}
}
}
@@ -104,7 +104,7 @@ pub fn parse_options(options: &Options) -> ParsedOptions {
}
- ParsedOptions {
+ Ok(ParsedOptions {
freq,
interval: partial_options.interval.unwrap(),
count: partial_options.count,
@@ -124,7 +124,7 @@ pub fn parse_options(options: &Options) -> ParsedOptions {
bysecond: partial_options.bysecond.unwrap_or(vec![]),
bynweekday: partial_options.bynweekday.unwrap_or(vec![]),
byeaster: partial_options.byeaster,
- }
+ })
}
fn is_some_and_not_empty<T>(v: &Option<Vec<T>>) -> bool {