Skip to content

Commit 9b3498a

Browse files
committed
Migrate to core::error::Error
Stabilized in rust 1.81, behind a feature flag so as to not bump the current MSRV of 1.61.
1 parent 3b4af71 commit 9b3498a

File tree

7 files changed

+30
-4
lines changed

7 files changed

+30
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ winapi = ["windows-link"]
2525
std = ["alloc"]
2626
clock = ["winapi", "iana-time-zone", "android-tzdata", "now"]
2727
now = ["std"]
28+
core_error = []
2829
oldtime = []
2930
wasmbind = ["wasm-bindgen", "js-sys"]
3031
unstable-locales = ["pure-rust-locales"]

src/format/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
3434
#[cfg(all(feature = "alloc", not(feature = "std"), not(test)))]
3535
use alloc::boxed::Box;
36+
#[cfg(all(feature = "core_error", not(feature = "std")))]
37+
use core::error::Error;
3638
use core::fmt;
3739
use core::str::FromStr;
3840
#[cfg(feature = "std")]
@@ -450,7 +452,7 @@ impl fmt::Display for ParseError {
450452
}
451453
}
452454

453-
#[cfg(feature = "std")]
455+
#[cfg(any(feature = "core_error", feature = "std"))]
454456
impl Error for ParseError {
455457
#[allow(deprecated)]
456458
fn description(&self) -> &str {

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@
512512
extern crate alloc;
513513

514514
mod time_delta;
515-
#[cfg(feature = "std")]
516515
#[doc(no_inline)]
516+
#[cfg(any(feature = "std", feature = "core_error"))]
517517
pub use time_delta::OutOfRangeError;
518518
pub use time_delta::TimeDelta;
519519

@@ -690,6 +690,9 @@ impl fmt::Debug for OutOfRange {
690690
#[cfg(feature = "std")]
691691
impl std::error::Error for OutOfRange {}
692692

693+
#[cfg(all(not(feature = "std"), feature = "core_error"))]
694+
impl core::error::Error for OutOfRange {}
695+
693696
/// Workaround because `?` is not (yet) available in const context.
694697
#[macro_export]
695698
#[doc(hidden)]

src/month.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ pub struct ParseMonthError {
272272
#[cfg(feature = "std")]
273273
impl std::error::Error for ParseMonthError {}
274274

275+
#[cfg(all(not(feature = "std"), feature = "core_error"))]
276+
impl core::error::Error for ParseMonthError {}
277+
275278
impl fmt::Display for ParseMonthError {
276279
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
277280
write!(f, "ParseMonthError {{ .. }}")

src/round.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ pub trait DurationRound: Sized {
109109
type Err: std::error::Error;
110110

111111
/// Error that can occur in rounding or truncating
112-
#[cfg(not(feature = "std"))]
112+
#[cfg(all(not(feature = "std"), feature = "core_error"))]
113+
type Err: core::error::Error;
114+
115+
/// Error that can occur in rounding or truncating
116+
#[cfg(all(not(feature = "std"), not(feature = "core_error")))]
113117
type Err: fmt::Debug + fmt::Display;
114118

115119
/// Return a copy rounded by TimeDelta.
@@ -362,6 +366,14 @@ impl std::error::Error for RoundingError {
362366
}
363367
}
364368

369+
#[cfg(all(not(feature = "std"), feature = "core_error"))]
370+
impl core::error::Error for RoundingError {
371+
#[allow(deprecated)]
372+
fn description(&self) -> &str {
373+
"error from rounding or truncating with DurationRound"
374+
}
375+
}
376+
365377
#[cfg(test)]
366378
mod tests {
367379
use super::{DurationRound, RoundingError, SubsecRound, TimeDelta};

src/time_delta.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
//! Temporal quantification
1212
13+
#[cfg(all(not(feature = "std"), feature = "core_error"))]
14+
use core::error::Error;
1315
use core::fmt;
1416
use core::ops::{Add, AddAssign, Div, Mul, Neg, Sub, SubAssign};
1517
use core::time::Duration;
@@ -630,7 +632,7 @@ impl fmt::Display for OutOfRangeError {
630632
}
631633
}
632634

633-
#[cfg(feature = "std")]
635+
#[cfg(any(feature = "std", feature = "core_error"))]
634636
impl Error for OutOfRangeError {
635637
#[allow(deprecated)]
636638
fn description(&self) -> &str {

src/weekday.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ pub struct ParseWeekdayError {
238238
pub(crate) _dummy: (),
239239
}
240240

241+
#[cfg(all(not(feature = "std"), feature = "core_error"))]
242+
impl core::error::Error for ParseWeekdayError {}
243+
241244
#[cfg(feature = "std")]
242245
impl std::error::Error for ParseWeekdayError {}
243246

0 commit comments

Comments
 (0)