Skip to content

Commit

Permalink
Fully convert Parsed::set_* to new error type
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Mar 12, 2024
1 parent 3aefc88 commit 983d846
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 148 deletions.
10 changes: 5 additions & 5 deletions src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{Fixed, InternalFixed, InternalInternal, Item, Numeric, Pad, Parsed};
use super::{BAD_FORMAT, INVALID, OUT_OF_RANGE, TOO_LONG, TOO_SHORT};
use crate::{DateTime, Error, FixedOffset, Weekday};

fn set_weekday_with_num_days_from_sunday(p: &mut Parsed, v: i64) -> ParseResult<&mut Parsed> {
fn set_weekday_with_num_days_from_sunday(p: &mut Parsed, v: i64) -> Result<&mut Parsed, Error> {
p.set_weekday(match v {
0 => Weekday::Sun,
1 => Weekday::Mon,
Expand All @@ -23,11 +23,11 @@ fn set_weekday_with_num_days_from_sunday(p: &mut Parsed, v: i64) -> ParseResult<
4 => Weekday::Thu,
5 => Weekday::Fri,
6 => Weekday::Sat,
_ => return Err(OUT_OF_RANGE),
_ => return Err(Error::InvalidArgument),

Check warning on line 26 in src/format/parse.rs

View check run for this annotation

Codecov / codecov/patch

src/format/parse.rs#L26

Added line #L26 was not covered by tests
})
}

fn set_weekday_with_number_from_monday(p: &mut Parsed, v: i64) -> ParseResult<&mut Parsed> {
fn set_weekday_with_number_from_monday(p: &mut Parsed, v: i64) -> Result<&mut Parsed, Error> {
p.set_weekday(match v {
1 => Weekday::Mon,
2 => Weekday::Tue,
Expand All @@ -36,7 +36,7 @@ fn set_weekday_with_number_from_monday(p: &mut Parsed, v: i64) -> ParseResult<&m
5 => Weekday::Fri,
6 => Weekday::Sat,
7 => Weekday::Sun,
_ => return Err(OUT_OF_RANGE),
_ => return Err(Error::InvalidArgument),

Check warning on line 39 in src/format/parse.rs

View check run for this annotation

Codecov / codecov/patch

src/format/parse.rs#L39

Added line #L39 was not covered by tests
})
}

Expand Down Expand Up @@ -339,7 +339,7 @@ where

Item::Numeric(ref spec, ref _pad) => {
use super::Numeric::*;
type Setter = fn(&mut Parsed, i64) -> ParseResult<&mut Parsed>;
type Setter = fn(&mut Parsed, i64) -> Result<&mut Parsed, Error>;

let (width, signed, set): (usize, bool, Setter) = match *spec {
Year => (4, true, Parsed::set_year),
Expand Down

0 comments on commit 983d846

Please sign in to comment.