Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Forked at: aaee912
Parent branch: origin/master
  • Loading branch information
cecton committed Jul 12, 2020
1 parent fcc7d5d commit e95b218
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -402,11 +405,14 @@ enum FormatErrorKind {
}

/// Same as `Result<T, FormatError>`.
#[cfg(any(feature = "alloc", feature = "std", test))]
pub type FormatResult<T> = Result<T, FormatError>;

#[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 => {
Expand All @@ -425,6 +431,7 @@ impl Error for FormatError {
}
}

#[cfg(any(feature = "alloc", feature = "std", test))]
impl From<fmt::Error> for FormatError {
fn from(_err: fmt::Error) -> Self {
FormatError(FormatErrorKind::Format)
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit e95b218

Please sign in to comment.