From e95b218319439ad790cdf38f3bb878c94db85da0 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Sun, 12 Jul 2020 12:32:09 +0200 Subject: [PATCH] WIP Forked at: aaee91222802471c656480ddb49b6f1e53a69a96 Parent branch: origin/master --- src/format/mod.rs | 7 +++++++ src/lib.rs | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/format/mod.rs b/src/format/mod.rs index 1d4c7cb57e..ad889c3844 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -38,6 +38,7 @@ use offset::{FixedOffset, Offset}; use {Datelike, Timelike}; use {ParseWeekdayError, Weekday}; +#[cfg(any(feature = "alloc", feature = "std", test))] mod locales; pub use self::parse::parse; @@ -382,9 +383,11 @@ const BAD_FORMAT: ParseError = ParseError(ParseErrorKind::BadFormat); /// An error from a "format" function. #[derive(Debug, Clone, PartialEq, Eq, Copy)] +#[cfg(any(feature = "alloc", feature = "std", test))] pub struct FormatError(FormatErrorKind); /// The category of format error. +#[cfg(any(feature = "alloc", feature = "std", test))] #[derive(Debug, Clone, PartialEq, Eq, Copy)] enum FormatErrorKind { /// The locale is unknown or not available. @@ -402,11 +405,14 @@ enum FormatErrorKind { } /// Same as `Result`. +#[cfg(any(feature = "alloc", feature = "std", test))] pub type FormatResult = Result; +#[cfg(any(feature = "alloc", feature = "std", test))] impl fmt::Display for FormatError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.0 { + #[cfg(feature = "locales")] FormatErrorKind::UnknownLocale => write!(f, "the locale is unknown or not available"), FormatErrorKind::Format => write!(f, "{}", fmt::Error), FormatErrorKind::InsufficientArguments => { @@ -425,6 +431,7 @@ impl Error for FormatError { } } +#[cfg(any(feature = "alloc", feature = "std", test))] impl From for FormatError { fn from(_err: fmt::Error) -> Self { FormatError(FormatErrorKind::Format) diff --git a/src/lib.rs b/src/lib.rs index b80529f155..1020770b00 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -452,7 +452,9 @@ pub use date::{Date, MAX_DATE, MIN_DATE}; #[cfg(feature = "rustc-serialize")] pub use datetime::rustc_serialize::TsSeconds; pub use datetime::{DateTime, SecondsFormat, MAX_DATETIME, MIN_DATETIME}; -pub use format::{FormatError, FormatResult, ParseError, ParseResult}; +#[cfg(any(feature = "alloc", feature = "std", test))] +pub use format::{FormatError, FormatResult}; +pub use format::{ParseError, ParseResult}; #[doc(no_inline)] pub use naive::{IsoWeek, NaiveDate, NaiveDateTime, NaiveTime}; #[cfg(feature = "clock")]