Skip to content

Commit

Permalink
Don't make unstable-locales depend on alloc feature
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Sep 23, 2023
1 parent bfc7b26 commit 68a141e
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ std = ["alloc"]
clock = ["std", "winapi", "iana-time-zone", "android-tzdata"]
oldtime = []
wasmbind = ["wasm-bindgen", "js-sys"]
unstable-locales = ["pure-rust-locales", "alloc"]
unstable-locales = ["pure-rust-locales"]
__internal_bench = []

[dependencies]
Expand Down
6 changes: 3 additions & 3 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use core::{fmt, hash};
use rkyv::{Archive, Deserialize, Serialize};

use crate::duration::Duration as OldDuration;
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
use crate::format::Locale;
#[cfg(feature = "alloc")]
use crate::format::{DelayedFormat, Item, StrftimeItems};
Expand Down Expand Up @@ -355,7 +355,7 @@ where
}

/// Formats the date with the specified formatting items and locale.
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[inline]
#[must_use]
pub fn format_localized_with_items<'a, I, B>(
Expand All @@ -379,7 +379,7 @@ where
/// Formats the date with the specified format string and locale.
/// See the [`crate::format::strftime`] module
/// on the supported escape sequences.
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[inline]
#[must_use]
pub fn format_localized<'a>(
Expand Down
6 changes: 3 additions & 3 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use core::{fmt, hash, str};
use std::time::{SystemTime, UNIX_EPOCH};

use crate::duration::Duration as OldDuration;
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
use crate::format::Locale;
use crate::format::{
parse, parse_and_remainder, parse_rfc3339, Fixed, Item, ParseError, ParseResult, Parsed,
Expand Down Expand Up @@ -891,7 +891,7 @@ where
}

/// Formats the combined date and time with the specified formatting items and locale.
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[inline]
#[must_use]
pub fn format_localized_with_items<'a, I, B>(
Expand All @@ -918,7 +918,7 @@ where
///
/// See the [`crate::format::strftime`] module on the supported escape
/// sequences.
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[inline]
#[must_use]
pub fn format_localized<'a>(
Expand Down
8 changes: 5 additions & 3 deletions src/format/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ use crate::{NaiveDate, NaiveTime, Weekday};

#[cfg(feature = "alloc")]
use super::locales;
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
use super::Locale;
#[cfg(any(feature = "alloc", feature = "serde", feature = "rustc-serialize"))]
use super::{Colons, OffsetFormat, OffsetPrecision, Pad};
#[cfg(feature = "alloc")]
use super::{Fixed, InternalFixed, InternalInternal, Item, Locale, Numeric};
use super::{Fixed, InternalFixed, InternalInternal, Item, Numeric};
#[cfg(feature = "alloc")]
use locales::*;

Expand Down Expand Up @@ -188,7 +190,7 @@ pub fn format_item(

/// Tries to format given arguments with given formatting items.
/// Internally used by `DelayedFormat`.
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[deprecated(since = "0.4.32", note = "Use DelayedFormat::fmt instead")]
pub fn format_localized<'a, I, B>(
w: &mut fmt::Formatter,
Expand All @@ -213,7 +215,7 @@ where
}

/// Formats single formatting item
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[deprecated(since = "0.4.32", note = "Use DelayedFormat::fmt instead")]
pub fn format_item_localized(
w: &mut fmt::Formatter,
Expand Down
10 changes: 5 additions & 5 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ pub(crate) mod scan;

pub mod strftime;

#[cfg(feature = "alloc")]
#[allow(unused)]
// TODO: remove '#[allow(unused)]' once we use this module for parsing or something else that does
// not require `alloc`.
pub(crate) mod locales;

pub(crate) use formatting::write_hundreds;
Expand All @@ -59,13 +61,11 @@ pub(crate) use formatting::write_rfc3339;
#[cfg(feature = "alloc")]
#[allow(deprecated)]
pub use formatting::{format, format_item, DelayedFormat};
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[allow(deprecated)]
pub use formatting::{format_item_localized, format_localized};
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[cfg(feature = "unstable-locales")]
pub use locales::Locale;
#[cfg(all(not(feature = "unstable-locales"), feature = "alloc"))]
pub(crate) use locales::Locale;
pub(crate) use parse::parse_rfc3339;
pub use parse::{parse, parse_and_remainder};
pub use parsed::Parsed;
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
//! # #[allow(unused_imports)]
//! use chrono::prelude::*;
//!
//! # #[cfg(feature = "unstable-locales")]
//! # #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
//! # fn test() {
//! let dt = Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap();
//! assert_eq!(dt.format("%Y-%m-%d %H:%M:%S").to_string(), "2014-11-28 12:00:09");
Expand All @@ -244,9 +244,9 @@
//! let dt_nano = NaiveDate::from_ymd_opt(2014, 11, 28).unwrap().and_hms_nano_opt(12, 0, 9, 1).unwrap().and_local_timezone(Utc).unwrap();
//! assert_eq!(format!("{:?}", dt_nano), "2014-11-28T12:00:09.000000001Z");
//! # }
//! # #[cfg(not(feature = "unstable-locales"))]
//! # #[cfg(not(all(feature = "unstable-locales", feature = "alloc")))]
//! # fn test() {}
//! # if cfg!(feature = "unstable-locales") {
//! # if cfg!(all(feature = "unstable-locales", feature = "alloc")) {
//! # test();
//! # }
//! ```
Expand Down Expand Up @@ -489,7 +489,7 @@ pub mod prelude {
#[cfg(feature = "clock")]
#[doc(no_inline)]
pub use crate::Local;
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[doc(no_inline)]
pub use crate::Locale;
#[doc(no_inline)]
Expand Down
6 changes: 3 additions & 3 deletions src/naive/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use core::{fmt, str};
use rkyv::{Archive, Deserialize, Serialize};

/// L10n locales.
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
use pure_rust_locales::Locale;

use crate::duration::Duration as OldDuration;
Expand Down Expand Up @@ -1319,7 +1319,7 @@ impl NaiveDate {
}

/// Formats the date with the specified formatting items and locale.
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[inline]
#[must_use]
pub fn format_localized_with_items<'a, I, B>(
Expand All @@ -1338,7 +1338,7 @@ impl NaiveDate {
///
/// See the [`crate::format::strftime`] module on the supported escape
/// sequences.
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[inline]
#[must_use]
pub fn format_localized<'a>(
Expand Down

0 comments on commit 68a141e

Please sign in to comment.