Skip to content

Commit

Permalink
Don't require alloc for unstable-locales feature
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jul 23, 2023
1 parent 3c2c307 commit 24b3fcb
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ std = []
clock = ["std", "winapi", "iana-time-zone"]
oldtime = ["time"]
wasmbind = ["wasm-bindgen", "js-sys"]
unstable-locales = ["pure-rust-locales", "alloc"]
unstable-locales = ["pure-rust-locales"]
__internal_bench = ["criterion"]
__doctest = []

Expand Down
8 changes: 3 additions & 5 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use core::{fmt, hash};
#[cfg(feature = "rkyv")]
use rkyv::{Archive, Deserialize, Serialize};

#[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 @@ -357,8 +357,7 @@ where
}

/// Formats the date with the specified formatting items and locale.
#[cfg(feature = "unstable-locales")]
#[cfg_attr(docsrs, doc(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 @@ -382,8 +381,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_attr(docsrs, doc(cfg(feature = "unstable-locales")))]
#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))]
#[inline]
#[must_use]
pub fn format_localized<'a>(
Expand Down
8 changes: 3 additions & 5 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::time::{SystemTime, UNIX_EPOCH};

#[cfg(any(feature = "alloc", feature = "std"))]
use crate::format::DelayedFormat;
#[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, ParseError, ParseResult, Parsed, StrftimeItems};
use crate::format::{Fixed, Item};
Expand Down Expand Up @@ -834,8 +834,7 @@ where
}

/// Formats the combined date and time with the specified formatting items and locale.
#[cfg(feature = "unstable-locales")]
#[cfg_attr(docsrs, doc(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 @@ -862,8 +861,7 @@ where
///
/// See the [`crate::format::strftime`] module on the supported escape
/// sequences.
#[cfg(feature = "unstable-locales")]
#[cfg_attr(docsrs, doc(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: 2 additions & 4 deletions src/format/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ pub fn format_item(

/// Tries to format given arguments with given formatting items.
/// Internally used by `DelayedFormat`.
#[cfg(feature = "unstable-locales")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))]
#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))]
#[deprecated(since = "0.4.27")]
pub fn format_localized<'a, I, B>(
w: &mut fmt::Formatter,
Expand All @@ -496,8 +495,7 @@ where
}

/// Formats single formatting item
#[cfg(feature = "unstable-locales")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))]
#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))]
#[deprecated(since = "0.4.27")]
pub fn format_item_localized(
w: &mut fmt::Formatter,
Expand Down
2 changes: 1 addition & 1 deletion src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub use formatting::Formatter;
#[cfg(any(feature = "alloc", feature = "std"))]
pub use formatting::{format, format_item, DelayedFormat};
#[allow(deprecated)]
#[cfg(feature = "unstable-locales")]
#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))]
pub use formatting::{format_item_localized, format_localized};
#[cfg(any(feature = "alloc", feature = "std"))]
pub(crate) use formatting::{write_rfc2822, write_rfc3339};
Expand Down
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,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 @@ -246,9 +246,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 @@ -426,8 +426,7 @@ pub mod prelude {
#[cfg_attr(docsrs, doc(cfg(feature = "clock")))]
#[doc(no_inline)]
pub use crate::Local;
#[cfg(feature = "unstable-locales")]
#[cfg_attr(docsrs, doc(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 Expand Up @@ -458,7 +457,6 @@ pub use datetime::{DateTime, SecondsFormat, MAX_DATETIME, MIN_DATETIME};
pub mod format;
/// L10n locales.
#[cfg(feature = "unstable-locales")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))]
pub use format::Locale;
pub use format::{ParseError, ParseResult};

Expand Down
8 changes: 3 additions & 5 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;

#[cfg(any(feature = "alloc", feature = "std"))]
Expand Down Expand Up @@ -1304,8 +1304,7 @@ impl NaiveDate {
}

/// Formats the date with the specified formatting items and locale.
#[cfg(feature = "unstable-locales")]
#[cfg_attr(docsrs, doc(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 @@ -1324,8 +1323,7 @@ impl NaiveDate {
///
/// See the [`crate::format::strftime`] module on the supported escape
/// sequences.
#[cfg(feature = "unstable-locales")]
#[cfg_attr(docsrs, doc(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 24b3fcb

Please sign in to comment.