Don't make unstable-locales depend on alloc feature

This commit is contained in:
Paul Dicker 2023-09-23 12:39:48 +02:00 committed by Paul Dicker
parent bfc7b26239
commit 68a141eba0
7 changed files with 24 additions and 22 deletions

View File

@ -25,7 +25,7 @@ std = ["alloc"]
clock = ["std", "winapi", "iana-time-zone", "android-tzdata"] clock = ["std", "winapi", "iana-time-zone", "android-tzdata"]
oldtime = [] oldtime = []
wasmbind = ["wasm-bindgen", "js-sys"] wasmbind = ["wasm-bindgen", "js-sys"]
unstable-locales = ["pure-rust-locales", "alloc"] unstable-locales = ["pure-rust-locales"]
__internal_bench = [] __internal_bench = []
[dependencies] [dependencies]

View File

@ -14,7 +14,7 @@ use core::{fmt, hash};
use rkyv::{Archive, Deserialize, Serialize}; use rkyv::{Archive, Deserialize, Serialize};
use crate::duration::Duration as OldDuration; use crate::duration::Duration as OldDuration;
#[cfg(feature = "unstable-locales")] #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
use crate::format::Locale; use crate::format::Locale;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use crate::format::{DelayedFormat, Item, StrftimeItems}; use crate::format::{DelayedFormat, Item, StrftimeItems};
@ -355,7 +355,7 @@ where
} }
/// Formats the date with the specified formatting items and locale. /// Formats the date with the specified formatting items and locale.
#[cfg(feature = "unstable-locales")] #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[inline] #[inline]
#[must_use] #[must_use]
pub fn format_localized_with_items<'a, I, B>( pub fn format_localized_with_items<'a, I, B>(
@ -379,7 +379,7 @@ where
/// Formats the date with the specified format string and locale. /// Formats the date with the specified format string and locale.
/// See the [`crate::format::strftime`] module /// See the [`crate::format::strftime`] module
/// on the supported escape sequences. /// on the supported escape sequences.
#[cfg(feature = "unstable-locales")] #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[inline] #[inline]
#[must_use] #[must_use]
pub fn format_localized<'a>( pub fn format_localized<'a>(

View File

@ -15,7 +15,7 @@ use core::{fmt, hash, str};
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use crate::duration::Duration as OldDuration; use crate::duration::Duration as OldDuration;
#[cfg(feature = "unstable-locales")] #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
use crate::format::Locale; use crate::format::Locale;
use crate::format::{ use crate::format::{
parse, parse_and_remainder, parse_rfc3339, Fixed, Item, ParseError, ParseResult, Parsed, parse, parse_and_remainder, parse_rfc3339, Fixed, Item, ParseError, ParseResult, Parsed,
@ -891,7 +891,7 @@ where
} }
/// Formats the combined date and time with the specified formatting items and locale. /// 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] #[inline]
#[must_use] #[must_use]
pub fn format_localized_with_items<'a, I, B>( pub fn format_localized_with_items<'a, I, B>(
@ -918,7 +918,7 @@ where
/// ///
/// See the [`crate::format::strftime`] module on the supported escape /// See the [`crate::format::strftime`] module on the supported escape
/// sequences. /// sequences.
#[cfg(feature = "unstable-locales")] #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[inline] #[inline]
#[must_use] #[must_use]
pub fn format_localized<'a>( pub fn format_localized<'a>(

View File

@ -22,10 +22,12 @@ use crate::{NaiveDate, NaiveTime, Weekday};
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use super::locales; use super::locales;
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
use super::Locale;
#[cfg(any(feature = "alloc", feature = "serde", feature = "rustc-serialize"))] #[cfg(any(feature = "alloc", feature = "serde", feature = "rustc-serialize"))]
use super::{Colons, OffsetFormat, OffsetPrecision, Pad}; use super::{Colons, OffsetFormat, OffsetPrecision, Pad};
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use super::{Fixed, InternalFixed, InternalInternal, Item, Locale, Numeric}; use super::{Fixed, InternalFixed, InternalInternal, Item, Numeric};
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use locales::*; use locales::*;
@ -188,7 +190,7 @@ pub fn format_item(
/// Tries to format given arguments with given formatting items. /// Tries to format given arguments with given formatting items.
/// Internally used by `DelayedFormat`. /// 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")] #[deprecated(since = "0.4.32", note = "Use DelayedFormat::fmt instead")]
pub fn format_localized<'a, I, B>( pub fn format_localized<'a, I, B>(
w: &mut fmt::Formatter, w: &mut fmt::Formatter,
@ -213,7 +215,7 @@ where
} }
/// Formats single formatting item /// 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")] #[deprecated(since = "0.4.32", note = "Use DelayedFormat::fmt instead")]
pub fn format_item_localized( pub fn format_item_localized(
w: &mut fmt::Formatter, w: &mut fmt::Formatter,

View File

@ -48,7 +48,9 @@ pub(crate) mod scan;
pub mod strftime; 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) mod locales;
pub(crate) use formatting::write_hundreds; pub(crate) use formatting::write_hundreds;
@ -59,13 +61,11 @@ pub(crate) use formatting::write_rfc3339;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
#[allow(deprecated)] #[allow(deprecated)]
pub use formatting::{format, format_item, DelayedFormat}; pub use formatting::{format, format_item, DelayedFormat};
#[cfg(feature = "unstable-locales")] #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[allow(deprecated)] #[allow(deprecated)]
pub use formatting::{format_item_localized, format_localized}; pub use formatting::{format_item_localized, format_localized};
#[cfg(all(feature = "unstable-locales", feature = "alloc"))] #[cfg(feature = "unstable-locales")]
pub use locales::Locale; pub use locales::Locale;
#[cfg(all(not(feature = "unstable-locales"), feature = "alloc"))]
pub(crate) use locales::Locale;
pub(crate) use parse::parse_rfc3339; pub(crate) use parse::parse_rfc3339;
pub use parse::{parse, parse_and_remainder}; pub use parse::{parse, parse_and_remainder};
pub use parsed::Parsed; pub use parsed::Parsed;

View File

@ -227,7 +227,7 @@
//! # #[allow(unused_imports)] //! # #[allow(unused_imports)]
//! use chrono::prelude::*; //! use chrono::prelude::*;
//! //!
//! # #[cfg(feature = "unstable-locales")] //! # #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
//! # fn test() { //! # fn test() {
//! let dt = Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(); //! 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"); //! assert_eq!(dt.format("%Y-%m-%d %H:%M:%S").to_string(), "2014-11-28 12:00:09");
@ -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(); //! 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"); //! 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() {} //! # fn test() {}
//! # if cfg!(feature = "unstable-locales") { //! # if cfg!(all(feature = "unstable-locales", feature = "alloc")) {
//! # test(); //! # test();
//! # } //! # }
//! ``` //! ```
@ -489,7 +489,7 @@ pub mod prelude {
#[cfg(feature = "clock")] #[cfg(feature = "clock")]
#[doc(no_inline)] #[doc(no_inline)]
pub use crate::Local; pub use crate::Local;
#[cfg(feature = "unstable-locales")] #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[doc(no_inline)] #[doc(no_inline)]
pub use crate::Locale; pub use crate::Locale;
#[doc(no_inline)] #[doc(no_inline)]

View File

@ -13,7 +13,7 @@ use core::{fmt, str};
use rkyv::{Archive, Deserialize, Serialize}; use rkyv::{Archive, Deserialize, Serialize};
/// L10n locales. /// L10n locales.
#[cfg(feature = "unstable-locales")] #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
use pure_rust_locales::Locale; use pure_rust_locales::Locale;
use crate::duration::Duration as OldDuration; use crate::duration::Duration as OldDuration;
@ -1319,7 +1319,7 @@ impl NaiveDate {
} }
/// Formats the date with the specified formatting items and locale. /// Formats the date with the specified formatting items and locale.
#[cfg(feature = "unstable-locales")] #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[inline] #[inline]
#[must_use] #[must_use]
pub fn format_localized_with_items<'a, I, B>( pub fn format_localized_with_items<'a, I, B>(
@ -1338,7 +1338,7 @@ impl NaiveDate {
/// ///
/// See the [`crate::format::strftime`] module on the supported escape /// See the [`crate::format::strftime`] module on the supported escape
/// sequences. /// sequences.
#[cfg(feature = "unstable-locales")] #[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[inline] #[inline]
#[must_use] #[must_use]
pub fn format_localized<'a>( pub fn format_localized<'a>(