fix: Change error type to unit-like struct

This commit is contained in:
Kyle Bloom 2023-01-31 13:53:40 +00:00 committed by Marli Frost
parent 5726a07a76
commit 3f770178ec
2 changed files with 10 additions and 12 deletions

View file

@ -84,17 +84,15 @@ impl From<ZipError> for io::Error {
/// Error type for time parsing /// Error type for time parsing
#[derive(Debug)] #[derive(Debug)]
pub enum ZipDateTimeError { pub struct DateTimeRangeError;
/// The date was on or before 1980, or on or after 2107
DateTimeOutOfBounds,
}
impl fmt::Display for ZipDateTimeError { impl fmt::Display for DateTimeRangeError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self { write!(
ZipDateTimeError::DateTimeOutOfBounds => write!(fmt, "datetime out of bounds"), fmt,
} "a date could not be represented within the bounds the MS-DOS date range (1980-2107)"
)
} }
} }
impl Error for ZipDateTimeError {} impl Error for DateTimeRangeError {}

View file

@ -44,7 +44,7 @@ mod atomic {
} }
#[cfg(feature = "time")] #[cfg(feature = "time")]
use crate::result::ZipDateTimeError; use crate::result::DateTimeRangeError;
#[cfg(feature = "time")] #[cfg(feature = "time")]
use time::{error::ComponentRange, Date, Month, OffsetDateTime, PrimitiveDateTime, Time}; use time::{error::ComponentRange, Date, Month, OffsetDateTime, PrimitiveDateTime, Time};
@ -259,7 +259,7 @@ impl DateTime {
#[cfg(feature = "time")] #[cfg(feature = "time")]
impl TryFrom<OffsetDateTime> for DateTime { impl TryFrom<OffsetDateTime> for DateTime {
type Error = ZipDateTimeError; type Error = DateTimeRangeError;
fn try_from(dt: OffsetDateTime) -> Result<Self, Self::Error> { fn try_from(dt: OffsetDateTime) -> Result<Self, Self::Error> {
if dt.year() >= 1980 && dt.year() <= 2107 { if dt.year() >= 1980 && dt.year() <= 2107 {
@ -272,7 +272,7 @@ impl TryFrom<OffsetDateTime> for DateTime {
second: dt.second(), second: dt.second(),
}) })
} else { } else {
Err(ZipDateTimeError::DateTimeOutOfBounds) Err(DateTimeRangeError)
} }
} }
} }