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 22, 2023
1 parent 41e34ad commit f40e155
Show file tree
Hide file tree
Showing 7 changed files with 23 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 = []
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", any(feature = "alloc", feature = "std")))]
use crate::format::Locale;
#[cfg(any(feature = "alloc", feature = "std"))]
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", any(feature = "alloc", feature = "std")))]
#[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", any(feature = "alloc", feature = "std")))]
#[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", any(feature = "alloc", feature = "std")))]
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", any(feature = "alloc", feature = "std")))]
#[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", any(feature = "alloc", feature = "std")))]
#[inline]
#[must_use]
pub fn format_localized<'a>(
Expand Down
9 changes: 6 additions & 3 deletions src/format/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ use super::locales;
))]
use super::{Colons, OffsetFormat, OffsetPrecision, Pad};
#[cfg(any(feature = "alloc", feature = "std"))]
use super::{Fixed, InternalFixed, InternalInternal, Item, Locale, Numeric};
use super::{Fixed, InternalFixed, InternalInternal, Item, Numeric};
#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))]
use super::Locale;

#[cfg(any(feature = "alloc", feature = "std"))]
use locales::*;

Expand Down Expand Up @@ -203,7 +206,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", any(feature = "alloc", feature = "std")))]
#[deprecated(since = "0.4.32", note = "Use DelayedFormat::fmt instead")]
pub fn format_localized<'a, I, B>(
w: &mut fmt::Formatter,
Expand All @@ -228,7 +231,7 @@ where
}

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

pub mod strftime;

#[cfg(any(feature = "alloc", feature = "std"))]
#[allow(unused)] // TODO: remove 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 @@ -64,13 +64,11 @@ pub(crate) use formatting::write_rfc3339;
#[cfg(any(feature = "alloc", feature = "std"))]
#[allow(deprecated)]
pub use formatting::{format, format_item, DelayedFormat};
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))]
#[allow(deprecated)]
pub use formatting::{format_item_localized, format_localized};
#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))]
#[cfg(feature = "unstable-locales")]
pub use locales::Locale;
#[cfg(all(not(feature = "unstable-locales"), any(feature = "alloc", feature = "std")))]
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", any(feature = "alloc", feature = "std")))]
//! # 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", any(feature = "alloc", feature = "std"))))]
//! # fn test() {}
//! # if cfg!(feature = "unstable-locales") {
//! # if cfg!(all(feature = "unstable-locales", any(feature = "alloc", feature = "std"))) {
//! # 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", any(feature = "alloc", feature = "std")))]
#[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", any(feature = "alloc", feature = "std")))]
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", any(feature = "alloc", feature = "std")))]
#[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", any(feature = "alloc", feature = "std")))]
#[inline]
#[must_use]
pub fn format_localized<'a>(
Expand Down

0 comments on commit f40e155

Please sign in to comment.