Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ winapi = ["windows-link"]
std = ["alloc"]
clock = ["winapi", "iana-time-zone", "android-tzdata", "now"]
now = ["std"]
core-error = []
oldtime = []
wasmbind = ["wasm-bindgen", "js-sys"]
unstable-locales = ["pure-rust-locales"]
Expand Down
4 changes: 3 additions & 1 deletion src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#[cfg(all(feature = "alloc", not(feature = "std"), not(test)))]
use alloc::boxed::Box;
#[cfg(all(feature = "core-error", not(feature = "std")))]
use core::error::Error;
use core::fmt;
use core::str::FromStr;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -450,7 +452,7 @@ impl fmt::Display for ParseError {
}
}

#[cfg(feature = "std")]
#[cfg(any(feature = "core-error", feature = "std"))]
impl Error for ParseError {
#[allow(deprecated)]
fn description(&self) -> &str {
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@
extern crate alloc;

mod time_delta;
#[cfg(feature = "std")]
#[doc(no_inline)]
#[cfg(any(feature = "std", feature = "core-error"))]
pub use time_delta::OutOfRangeError;
pub use time_delta::TimeDelta;

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

#[cfg(all(not(feature = "std"), feature = "core-error"))]
impl core::error::Error for OutOfRange {}

/// Workaround because `?` is not (yet) available in const context.
#[macro_export]
#[doc(hidden)]
Expand Down
3 changes: 3 additions & 0 deletions src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ pub struct ParseMonthError {
#[cfg(feature = "std")]
impl std::error::Error for ParseMonthError {}

#[cfg(all(not(feature = "std"), feature = "core-error"))]
impl core::error::Error for ParseMonthError {}

impl fmt::Display for ParseMonthError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ParseMonthError {{ .. }}")
Expand Down
14 changes: 13 additions & 1 deletion src/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ pub trait DurationRound: Sized {
type Err: std::error::Error;

/// Error that can occur in rounding or truncating
#[cfg(not(feature = "std"))]
#[cfg(all(not(feature = "std"), feature = "core-error"))]
type Err: core::error::Error;

/// Error that can occur in rounding or truncating
#[cfg(all(not(feature = "std"), not(feature = "core-error")))]
type Err: fmt::Debug + fmt::Display;

/// Return a copy rounded by TimeDelta.
Expand Down Expand Up @@ -362,6 +366,14 @@ impl std::error::Error for RoundingError {
}
}

#[cfg(all(not(feature = "std"), feature = "core-error"))]
impl core::error::Error for RoundingError {
#[allow(deprecated)]
fn description(&self) -> &str {
"error from rounding or truncating with DurationRound"
}
}

#[cfg(test)]
mod tests {
use super::{DurationRound, RoundingError, SubsecRound, TimeDelta};
Expand Down
4 changes: 3 additions & 1 deletion src/time_delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

//! Temporal quantification

#[cfg(all(not(feature = "std"), feature = "core-error"))]
use core::error::Error;
use core::fmt;
use core::ops::{Add, AddAssign, Div, Mul, Neg, Sub, SubAssign};
use core::time::Duration;
Expand Down Expand Up @@ -630,7 +632,7 @@ impl fmt::Display for OutOfRangeError {
}
}

#[cfg(feature = "std")]
#[cfg(any(feature = "std", feature = "core-error"))]
impl Error for OutOfRangeError {
#[allow(deprecated)]
fn description(&self) -> &str {
Expand Down
3 changes: 3 additions & 0 deletions src/weekday.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ pub struct ParseWeekdayError {
pub(crate) _dummy: (),
}

#[cfg(all(not(feature = "std"), feature = "core-error"))]
impl core::error::Error for ParseWeekdayError {}

#[cfg(feature = "std")]
impl std::error::Error for ParseWeekdayError {}

Expand Down
Loading