summaryrefslogtreecommitdiffstats
path: root/vendor/icu_provider/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
commit837b550238aa671a591ccf282dddeab29cadb206 (patch)
tree914b6b8862bace72bd3245ca184d374b08d8a672 /vendor/icu_provider/src
parentAdding debian version 1.70.0+dfsg2-1. (diff)
downloadrustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz
rustc-837b550238aa671a591ccf282dddeab29cadb206.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/icu_provider/src')
-rw-r--r--vendor/icu_provider/src/any.rs77
-rw-r--r--vendor/icu_provider/src/buf.rs48
-rw-r--r--vendor/icu_provider/src/data_provider.rs4
-rw-r--r--vendor/icu_provider/src/datagen/heap_measure.rs59
-rw-r--r--vendor/icu_provider/src/datagen/mod.rs23
-rw-r--r--vendor/icu_provider/src/datagen/payload.rs13
-rw-r--r--vendor/icu_provider/src/dynutil.rs2
-rw-r--r--vendor/icu_provider/src/error.rs31
-rw-r--r--vendor/icu_provider/src/hello_world.rs77
-rw-r--r--vendor/icu_provider/src/helpers.rs108
-rw-r--r--vendor/icu_provider/src/key.rs8
-rw-r--r--vendor/icu_provider/src/lib.rs139
-rw-r--r--vendor/icu_provider/src/marker.rs16
-rw-r--r--vendor/icu_provider/src/request.rs7
-rw-r--r--vendor/icu_provider/src/response.rs14
-rw-r--r--vendor/icu_provider/src/serde/borrow_de_utils.rs2
-rw-r--r--vendor/icu_provider/src/serde/mod.rs3
17 files changed, 314 insertions, 317 deletions
diff --git a/vendor/icu_provider/src/any.rs b/vendor/icu_provider/src/any.rs
index 989438c6b..c3af61fed 100644
--- a/vendor/icu_provider/src/any.rs
+++ b/vendor/icu_provider/src/any.rs
@@ -65,6 +65,7 @@ pub struct AnyPayload {
/// The [`DataMarker`] marker type for [`AnyPayload`].
#[allow(clippy::exhaustive_structs)] // marker type
+#[derive(Debug)]
pub struct AnyMarker;
impl DataMarker for AnyMarker {
@@ -73,7 +74,7 @@ impl DataMarker for AnyMarker {
impl<M> crate::dynutil::UpcastDataPayload<M> for AnyMarker
where
- M: DataMarker + 'static,
+ M: DataMarker,
M::Yokeable: MaybeSendSync,
{
#[inline]
@@ -90,7 +91,7 @@ impl AnyPayload {
/// the type stored in the `AnyPayload`.
pub fn downcast<M>(self) -> Result<DataPayload<M>, DataError>
where
- M: DataMarker + 'static,
+ M: DataMarker,
// For the StructRef case:
M::Yokeable: ZeroFrom<'static, M::Yokeable>,
// For the PayloadRc case:
@@ -118,7 +119,7 @@ impl AnyPayload {
/// Clones and then transforms a type-erased `AnyPayload` into a concrete `DataPayload<M>`.
pub fn downcast_cloned<M>(&self) -> Result<DataPayload<M>, DataError>
where
- M: DataMarker + 'static,
+ M: DataMarker,
// For the StructRef case:
M::Yokeable: ZeroFrom<'static, M::Yokeable>,
// For the PayloadRc case:
@@ -162,7 +163,7 @@ impl AnyPayload {
impl<M> DataPayload<M>
where
- M: DataMarker + 'static,
+ M: DataMarker,
M::Yokeable: MaybeSendSync,
{
/// Moves this DataPayload to the heap (requiring an allocation) and returns it as an
@@ -200,7 +201,7 @@ impl DataPayload<AnyMarker> {
#[inline]
pub fn downcast<M>(self) -> Result<DataPayload<M>, DataError>
where
- M: DataMarker + 'static,
+ M: DataMarker,
for<'a> YokeTraitHack<<M::Yokeable as Yokeable<'a>>::Output>: Clone,
M::Yokeable: ZeroFrom<'static, M::Yokeable>,
M::Yokeable: MaybeSendSync,
@@ -213,6 +214,7 @@ impl DataPayload<AnyMarker> {
///
/// Convertible to and from `DataResponse<AnyMarker>`.
#[allow(clippy::exhaustive_structs)] // this type is stable (the metadata is allowed to grow)
+#[derive(Debug)]
pub struct AnyResponse {
/// Metadata about the returned object.
pub metadata: DataResponseMetadata,
@@ -247,7 +249,7 @@ impl AnyResponse {
#[inline]
pub fn downcast<M>(self) -> Result<DataResponse<M>, DataError>
where
- M: DataMarker + 'static,
+ M: DataMarker,
for<'a> YokeTraitHack<<M::Yokeable as Yokeable<'a>>::Output>: Clone,
M::Yokeable: ZeroFrom<'static, M::Yokeable>,
M::Yokeable: MaybeSendSync,
@@ -261,7 +263,7 @@ impl AnyResponse {
/// Clones and then transforms a type-erased `AnyResponse` into a concrete `DataResponse<M>`.
pub fn downcast_cloned<M>(&self) -> Result<DataResponse<M>, DataError>
where
- M: DataMarker + 'static,
+ M: DataMarker,
M::Yokeable: ZeroFrom<'static, M::Yokeable>,
M::Yokeable: MaybeSendSync,
for<'a> YokeTraitHack<<M::Yokeable as Yokeable<'a>>::Output>: Clone,
@@ -279,7 +281,7 @@ impl AnyResponse {
impl<M> DataResponse<M>
where
- M: DataMarker + 'static,
+ M: DataMarker,
M::Yokeable: MaybeSendSync,
{
/// Moves the inner DataPayload to the heap (requiring an allocation) and returns it as an
@@ -301,24 +303,43 @@ where
/// use icu_provider::prelude::*;
/// use std::borrow::Cow;
///
-/// let any_response = HelloWorldProvider
-/// .as_any_provider()
-/// .load_any(
-/// HelloWorldV1Marker::KEY,
-/// DataRequest {
-/// locale: &icu_locid::locale!("de").into(),
-/// metadata: Default::default(),
-/// },
-/// )
-/// .expect("Load should succeed");
+/// let any_provider = HelloWorldProvider.as_any_provider();
///
-/// // Downcast to something useful
-/// let response: DataResponse<HelloWorldV1Marker> =
-/// any_response.downcast().expect("Types match");
+/// let req = DataRequest {
+/// locale: &icu_locid::locale!("de").into(),
+/// metadata: Default::default(),
+/// };
///
-/// let payload = response.take_payload().expect("Data should be present");
+/// // Downcasting manually
+/// assert_eq!(
+/// any_provider
+/// .load_any(HelloWorldV1Marker::KEY, req)
+/// .expect("load should succeed")
+/// .downcast::<HelloWorldV1Marker>()
+/// .expect("types should match")
+/// .take_payload()
+/// .unwrap()
+/// .get(),
+/// &HelloWorldV1 {
+/// message: Cow::Borrowed("Hallo Welt"),
+/// },
+/// );
///
-/// assert_eq!(payload.get().message, "Hallo Welt");
+/// // Downcasting automatically
+/// let downcasting_provider: &dyn DataProvider<HelloWorldV1Marker> =
+/// &any_provider.as_downcasting();
+///
+/// assert_eq!(
+/// downcasting_provider
+/// .load(req)
+/// .expect("load should succeed")
+/// .take_payload()
+/// .unwrap()
+/// .get(),
+/// &HelloWorldV1 {
+/// message: Cow::Borrowed("Hallo Welt"),
+/// },
+/// );
/// ```
pub trait AnyProvider {
/// Loads an [`AnyPayload`] according to the key and request.
@@ -333,6 +354,7 @@ impl<T: AnyProvider + ?Sized> AnyProvider for alloc::boxed::Box<T> {
/// A wrapper over `DynamicDataProvider<AnyMarker>` that implements `AnyProvider`
#[allow(clippy::exhaustive_structs)] // newtype
+#[derive(Debug)]
pub struct DynamicDataProviderAnyMarkerWrap<'a, P: ?Sized>(pub &'a P);
/// Blanket-implemented trait adding the [`Self::as_any_provider()`] function.
@@ -363,6 +385,7 @@ where
/// A wrapper over `AnyProvider` that implements `DynamicDataProvider<M>` via downcasting
#[allow(clippy::exhaustive_structs)] // newtype
+#[derive(Debug)]
pub struct DowncastingAnyProvider<'a, P: ?Sized>(pub &'a P);
/// Blanket-implemented trait adding the [`Self::as_downcasting()`] function.
@@ -384,7 +407,7 @@ where
impl<M, P> DataProvider<M> for DowncastingAnyProvider<'_, P>
where
P: AnyProvider + ?Sized,
- M: KeyedDataMarker + 'static,
+ M: KeyedDataMarker,
for<'a> YokeTraitHack<<M::Yokeable as Yokeable<'a>>::Output>: Clone,
M::Yokeable: ZeroFrom<'static, M::Yokeable>,
M::Yokeable: MaybeSendSync,
@@ -401,7 +424,7 @@ where
impl<M, P> DynamicDataProvider<M> for DowncastingAnyProvider<'_, P>
where
P: AnyProvider + ?Sized,
- M: DataMarker + 'static,
+ M: DataMarker,
for<'a> YokeTraitHack<<M::Yokeable as Yokeable<'a>>::Output>: Clone,
M::Yokeable: ZeroFrom<'static, M::Yokeable>,
M::Yokeable: MaybeSendSync,
@@ -434,7 +457,7 @@ mod test {
let any_payload = payload.wrap_into_any_payload();
assert_eq!(
"AnyPayload { inner: PayloadRc(Any { .. }), type_name: \"icu_provider::hello_world::HelloWorldV1Marker\" }",
- format!("{:?}", any_payload)
+ format!("{any_payload:?}")
);
struct WrongMarker;
@@ -446,7 +469,7 @@ mod test {
let err = any_payload.downcast::<WrongMarker>().unwrap_err();
assert_eq!(
"ICU4X data error: Mismatched types: tried to downcast with icu_provider::any::test::test_debug::WrongMarker, but actual type is different: icu_provider::hello_world::HelloWorldV1Marker",
- format!("{}", err)
+ format!("{err}")
);
}
diff --git a/vendor/icu_provider/src/buf.rs b/vendor/icu_provider/src/buf.rs
index 796ad32f3..5e8264998 100644
--- a/vendor/icu_provider/src/buf.rs
+++ b/vendor/icu_provider/src/buf.rs
@@ -11,6 +11,7 @@ use crate::prelude::*;
/// The data is expected to be deserialized before it can be used; see
/// [`DataPayload::into_deserialized`].
#[allow(clippy::exhaustive_structs)] // marker type
+#[derive(Debug)]
pub struct BufferMarker;
impl DataMarker for BufferMarker {
@@ -38,21 +39,46 @@ impl DataMarker for BufferMarker {
/// use icu_locid::locale;
/// use icu_provider::hello_world::*;
/// use icu_provider::prelude::*;
+/// use std::borrow::Cow;
///
/// let buffer_provider = HelloWorldProvider.into_json_provider();
///
-/// let data_provider = buffer_provider.as_deserializing();
+/// let req = DataRequest {
+/// locale: &locale!("de").into(),
+/// metadata: Default::default(),
+/// };
///
-/// let german_hello_world: DataPayload<HelloWorldV1Marker> = data_provider
-/// .load(DataRequest {
-/// locale: &locale!("de").into(),
-/// metadata: Default::default(),
-/// })
-/// .expect("Loading should succeed")
-/// .take_payload()
-/// .expect("Data should be present");
+/// // Deserializing manually
+/// assert_eq!(
+/// serde_json::from_slice::<HelloWorldV1>(
+/// buffer_provider
+/// .load_buffer(HelloWorldV1Marker::KEY, req)
+/// .expect("load should succeed")
+/// .take_payload()
+/// .unwrap()
+/// .get()
+/// )
+/// .expect("should deserialize"),
+/// HelloWorldV1 {
+/// message: Cow::Borrowed("Hallo Welt"),
+/// },
+/// );
///
-/// assert_eq!("Hallo Welt", german_hello_world.get().message);
+/// // Deserialize automatically
+/// let deserializing_provider: &dyn DataProvider<HelloWorldV1Marker> =
+/// &buffer_provider.as_deserializing();
+///
+/// assert_eq!(
+/// deserializing_provider
+/// .load(req)
+/// .expect("load should succeed")
+/// .take_payload()
+/// .unwrap()
+/// .get(),
+/// &HelloWorldV1 {
+/// message: Cow::Borrowed("Hallo Welt"),
+/// },
+/// );
/// # }
/// ```
///
@@ -85,7 +111,7 @@ pub enum BufferFormat {
Json,
/// Serialize using Bincode version 1.
Bincode1,
- /// Serialize using Postcard version 0.7.
+ /// Serialize using Postcard version 1.
Postcard1,
}
diff --git a/vendor/icu_provider/src/data_provider.rs b/vendor/icu_provider/src/data_provider.rs
index af98a252a..df821956a 100644
--- a/vendor/icu_provider/src/data_provider.rs
+++ b/vendor/icu_provider/src/data_provider.rs
@@ -53,8 +53,6 @@ mod test {
use super::*;
use crate::hello_world::*;
use crate::prelude::*;
- use crate::yoke::Yokeable;
- use crate::zerofrom;
use alloc::borrow::Cow;
use alloc::string::String;
use core::fmt::Debug;
@@ -68,7 +66,7 @@ mod test {
/// A data struct serialization-compatible with HelloWorldV1 used for testing mismatched types
#[derive(
- Serialize, Deserialize, Debug, Clone, Default, PartialEq, Yokeable, zerofrom::ZeroFrom,
+ Serialize, Deserialize, Debug, Clone, Default, PartialEq, yoke::Yokeable, zerofrom::ZeroFrom,
)]
struct HelloAlt {
#[zerofrom(clone)]
diff --git a/vendor/icu_provider/src/datagen/heap_measure.rs b/vendor/icu_provider/src/datagen/heap_measure.rs
deleted file mode 100644
index d451f3ebe..000000000
--- a/vendor/icu_provider/src/datagen/heap_measure.rs
+++ /dev/null
@@ -1,59 +0,0 @@
-// This file is part of ICU4X. For terms of use, please see the file
-// called LICENSE at the top level of the ICU4X source tree
-// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
-
-use crate::buf::{BufferFormat, BufferMarker};
-use crate::prelude::*;
-use yoke::trait_hack::YokeTraitHack;
-
-/// Stats on the heap size needed when attempting to zero-copy-deserialize
-/// a postcard-formatted data struct.
-#[derive(Debug, Copy, Clone, yoke::Yokeable, Default)]
-#[non_exhaustive]
-pub struct HeapStats {
- /// Total bytes allocated during deserialization
- pub total_bytes_allocated: u64,
- /// Total bytes allocated during deserialization that have not yet been freed
- pub net_bytes_allocated: usize,
-}
-
-/// The [`DataMarker`] marker type for [`HeapStats`].
-#[allow(clippy::exhaustive_structs)] // marker type
-pub struct HeapStatsMarker;
-
-impl DataMarker for HeapStatsMarker {
- type Yokeable = HeapStats;
-}
-
-impl DataPayload<BufferMarker> {
- /// Given a buffer known to be in postcard-0.7 format, attempt to zero-copy
- /// deserialize it and record the amount of heap allocations that occurred.
- ///
- /// Ideally, this number should be zero.
- ///
- /// [`dhat`]'s profiler must be initialized before using this.
- ///
- /// # Panics
- ///
- /// Panics if the buffer is not in postcard-0.7 format.
- #[allow(clippy::expect_used)] // The function documents when panics may occur.
- pub fn attempt_zero_copy_heap_size<M>(self) -> HeapStats
- where
- M: DataMarker,
- for<'a> &'a <M::Yokeable as yoke::Yokeable<'a>>::Output: serde::Serialize,
- for<'de> YokeTraitHack<<M::Yokeable as yoke::Yokeable<'de>>::Output>:
- serde::Deserialize<'de>,
- {
- let stats_before = dhat::HeapStats::get();
- // reify, but do nothing with the type
- let _reified_data: DataPayload<M> = self
- .into_deserialized(BufferFormat::Postcard1)
- .expect("Failed to deserialize BufferMarker as postcard-0.7");
- let stats_after = dhat::HeapStats::get();
-
- HeapStats {
- total_bytes_allocated: stats_after.total_bytes - stats_before.total_bytes,
- net_bytes_allocated: stats_after.curr_bytes - stats_before.curr_bytes,
- }
- }
-}
diff --git a/vendor/icu_provider/src/datagen/mod.rs b/vendor/icu_provider/src/datagen/mod.rs
index e52a19c4d..6596a0c07 100644
--- a/vendor/icu_provider/src/datagen/mod.rs
+++ b/vendor/icu_provider/src/datagen/mod.rs
@@ -9,11 +9,9 @@
//! This module can be enabled with the `datagen` Cargo feature on `icu_provider`.
mod data_conversion;
-mod heap_measure;
mod iter;
mod payload;
pub use data_conversion::DataConverter;
-pub use heap_measure::{HeapStats, HeapStatsMarker};
pub use iter::IterableDataProvider;
#[doc(hidden)] // exposed for make_exportable_provider
@@ -50,7 +48,7 @@ pub trait DataExporter: Sync {
/// A [`DynamicDataProvider`] that can be used for exporting data.
///
-/// Use [`make_exportable_provider`] to implement this.
+/// Use [`make_exportable_provider`](crate::make_exportable_provider) to implement this.
pub trait ExportableProvider: IterableDynamicDataProvider<ExportMarker> + Sync {}
impl<T> ExportableProvider for T where T: IterableDynamicDataProvider<ExportMarker> + Sync {}
@@ -97,24 +95,5 @@ macro_rules! make_exportable_provider {
}
}
}
-
- impl $crate::datagen::DataConverter<$crate::buf::BufferMarker, $crate::datagen::HeapStatsMarker> for $provider {
- fn convert(&self, key: $crate::DataKey, from: $crate::DataPayload<$crate::buf::BufferMarker>) -> Result<$crate::DataPayload<$crate::datagen::HeapStatsMarker>, ($crate::DataPayload<$crate::buf::BufferMarker>, $crate::DataError)> {
- #![allow(non_upper_case_globals)]
- // Reusing the struct names as identifiers
- $(
- const $struct_m: $crate::DataKeyHash = <$struct_m as $crate::KeyedDataMarker>::KEY.hashed();
- )+
- match key.hashed() {
- $(
- $struct_m => {
- let heap_stats = from.attempt_zero_copy_heap_size::<$struct_m>();
- return Ok($crate::DataPayload::from_owned(heap_stats));
- }
- )+,
- _ => Err((from, $crate::DataErrorKind::MissingDataKey.with_key(key)))
- }
- }
- }
};
}
diff --git a/vendor/icu_provider/src/datagen/payload.rs b/vendor/icu_provider/src/datagen/payload.rs
index b6ea8049f..c0d0a8bb9 100644
--- a/vendor/icu_provider/src/datagen/payload.rs
+++ b/vendor/icu_provider/src/datagen/payload.rs
@@ -4,9 +4,9 @@
use crate::dynutil::UpcastDataPayload;
use crate::prelude::*;
-use crate::yoke::*;
use alloc::boxed::Box;
use databake::{Bake, CrateEnv, TokenStream};
+use yoke::*;
trait ExportableYoke {
fn bake_yoke(&self, env: &CrateEnv) -> TokenStream;
@@ -43,6 +43,14 @@ pub struct ExportBox {
payload: Box<dyn ExportableYoke + Sync>,
}
+impl core::fmt::Debug for ExportBox {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ f.debug_struct("ExportBox")
+ .field("payload", &"<payload>")
+ .finish()
+ }
+}
+
impl<M> UpcastDataPayload<M> for ExportMarker
where
M: DataMarker,
@@ -76,7 +84,7 @@ impl DataPayload<ExportMarker> {
/// export
/// .serialize(&mut serde_json::Serializer::new(&mut buffer))
/// .expect("Serialization should succeed");
- /// assert_eq!("{\"message\":\"(und) Hello World\"}".as_bytes(), buffer);
+ /// assert_eq!(r#"{"message":"(und) Hello World"}"#.as_bytes(), buffer);
/// ```
pub fn serialize<S>(&self, serializer: S) -> Result<(), DataError>
where
@@ -130,6 +138,7 @@ impl DataPayload<ExportMarker> {
/// Marker type for [`ExportBox`].
#[allow(clippy::exhaustive_structs)] // marker type
+#[derive(Debug)]
pub struct ExportMarker {}
impl DataMarker for ExportMarker {
diff --git a/vendor/icu_provider/src/dynutil.rs b/vendor/icu_provider/src/dynutil.rs
index 89d7d7ded..5e1491e51 100644
--- a/vendor/icu_provider/src/dynutil.rs
+++ b/vendor/icu_provider/src/dynutil.rs
@@ -6,7 +6,7 @@
/// Trait to allow conversion from `DataPayload<T>` to `DataPayload<S>`.
///
-/// This trait can be manually implemented in order to enable [`impl_dynamic_data_provider`].
+/// This trait can be manually implemented in order to enable [`impl_dynamic_data_provider`](crate::impl_dynamic_data_provider).
///
/// [`DataPayload::downcast`]: crate::DataPayload::downcast
pub trait UpcastDataPayload<M>
diff --git a/vendor/icu_provider/src/error.rs b/vendor/icu_provider/src/error.rs
index 05a48f9b7..23f141e02 100644
--- a/vendor/icu_provider/src/error.rs
+++ b/vendor/icu_provider/src/error.rs
@@ -101,6 +101,9 @@ pub struct DataError {
/// Additional context, if available.
pub str_context: Option<&'static str>,
+
+ /// Whether this error was created in silent mode to not log.
+ pub silent: bool,
}
impl fmt::Display for DataError {
@@ -110,10 +113,10 @@ impl fmt::Display for DataError {
write!(f, ": {}", self.kind)?;
}
if let Some(key) = self.key {
- write!(f, " (key: {})", key)?;
+ write!(f, " (key: {key})")?;
}
if let Some(str_context) = self.str_context {
- write!(f, ": {}", str_context)?;
+ write!(f, ": {str_context}")?;
}
Ok(())
}
@@ -129,6 +132,7 @@ impl DataErrorKind {
kind: self,
key: None,
str_context: None,
+ silent: false,
}
}
@@ -165,6 +169,7 @@ impl DataError {
kind: DataErrorKind::Custom,
key: None,
str_context: Some(str_context),
+ silent: false,
}
}
@@ -175,6 +180,7 @@ impl DataError {
kind: self.kind,
key: Some(key),
str_context: self.str_context,
+ silent: self.silent,
}
}
@@ -185,6 +191,7 @@ impl DataError {
kind: self.kind,
key: self.key,
str_context: Some(context),
+ silent: self.silent,
}
}
@@ -199,10 +206,13 @@ impl DataError {
/// If the "log_error_context" Cargo feature is enabled, this logs the whole request. Either way,
/// it returns an error with the resource key portion of the request as context.
#[cfg_attr(not(feature = "log_error_context"), allow(unused_variables))]
- pub fn with_req(self, key: DataKey, req: DataRequest) -> Self {
+ pub fn with_req(mut self, key: DataKey, req: DataRequest) -> Self {
+ if req.metadata.silent {
+ self.silent = true;
+ }
// Don't write out a log for MissingDataKey since there is no context to add
#[cfg(feature = "log_error_context")]
- if self.kind != DataErrorKind::MissingDataKey {
+ if !self.silent && self.kind != DataErrorKind::MissingDataKey {
log::warn!("{} (key: {}, request: {})", self, key, req);
}
self.with_key(key)
@@ -216,7 +226,9 @@ impl DataError {
#[cfg_attr(not(feature = "log_error_context"), allow(unused_variables))]
pub fn with_path_context<P: AsRef<std::path::Path> + ?Sized>(self, path: &P) -> Self {
#[cfg(feature = "log_error_context")]
- log::warn!("{} (path: {:?})", self, path.as_ref());
+ if !self.silent {
+ log::warn!("{} (path: {:?})", self, path.as_ref());
+ }
self
}
@@ -228,7 +240,9 @@ impl DataError {
#[inline]
pub fn with_display_context<D: fmt::Display + ?Sized>(self, context: &D) -> Self {
#[cfg(feature = "log_error_context")]
- log::warn!("{}: {}", self, context);
+ if !self.silent {
+ log::warn!("{}: {}", self, context);
+ }
self
}
@@ -240,7 +254,9 @@ impl DataError {
#[inline]
pub fn with_debug_context<D: fmt::Debug + ?Sized>(self, context: &D) -> Self {
#[cfg(feature = "log_error_context")]
- log::warn!("{}: {:?}", self, context);
+ if !self.silent {
+ log::warn!("{}: {:?}", self, context);
+ }
self
}
@@ -250,6 +266,7 @@ impl DataError {
kind: DataErrorKind::MismatchedType(core::any::type_name::<T>()),
key: None,
str_context: None,
+ silent: false,
}
}
}
diff --git a/vendor/icu_provider/src/hello_world.rs b/vendor/icu_provider/src/hello_world.rs
index 7fd8289df..ec508ac48 100644
--- a/vendor/icu_provider/src/hello_world.rs
+++ b/vendor/icu_provider/src/hello_world.rs
@@ -6,22 +6,24 @@
#![allow(clippy::exhaustive_structs)] // data struct module
-use crate::buf::BufferFormat;
#[cfg(feature = "datagen")]
use crate::datagen::IterableDataProvider;
-use crate::helpers;
use crate::prelude::*;
-use crate::yoke::{self, *};
-use crate::zerofrom::{self, *};
use alloc::borrow::Cow;
use alloc::string::String;
use core::fmt::Debug;
use writeable::Writeable;
+use yoke::*;
+use zerofrom::*;
/// A struct containing "Hello World" in the requested language.
#[derive(Debug, PartialEq, Clone, Yokeable, ZeroFrom)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
-#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
+#[cfg_attr(
+ any(feature = "deserialize_json", feature = "datagen"),
+ derive(serde::Serialize)
+)]
+#[cfg_attr(feature = "datagen", derive(databake::Bake))]
#[cfg_attr(feature = "datagen", databake(path = icu_provider::hello_world))]
pub struct HelloWorldV1<'data> {
/// The translation of "Hello World".
@@ -40,6 +42,7 @@ impl Default for HelloWorldV1<'_> {
/// Marker type for [`HelloWorldV1`].
#[cfg_attr(feature = "datagen", derive(Default, databake::Bake))]
#[cfg_attr(feature = "datagen", databake(path = icu_provider::hello_world))]
+#[derive(Debug)]
pub struct HelloWorldV1Marker;
impl DataMarker for HelloWorldV1Marker {
@@ -98,9 +101,10 @@ impl HelloWorldProvider {
("zh", "你好世界"),
];
- /// Converts this provider into one that serves JSON blobs of the same data.
+ /// Converts this provider into a [`BufferProvider`] that uses JSON serialization.
+ #[cfg(feature = "deserialize_json")]
pub fn into_json_provider(self) -> HelloWorldJsonProvider {
- HelloWorldJsonProvider(self)
+ HelloWorldJsonProvider
}
}
@@ -110,13 +114,10 @@ impl DataProvider<HelloWorldV1Marker> for HelloWorldProvider {
let data = Self::DATA
.binary_search_by(|(k, _)| req.locale.strict_cmp(k.as_bytes()).reverse())
.map(|i| Self::DATA[i].1)
- .map(|s| HelloWorldV1 {
- message: Cow::Borrowed(s),
- })
.map_err(|_| DataErrorKind::MissingLocale.with_req(HelloWorldV1Marker::KEY, req))?;
Ok(DataResponse {
metadata: Default::default(),
- payload: Some(DataPayload::from_owned(data)),
+ payload: Some(DataPayload::from_static_str(data)),
})
}
}
@@ -130,12 +131,11 @@ impl DataPayload<HelloWorldV1Marker> {
}
}
+// AnyProvider support.
#[cfg(not(feature = "datagen"))]
impl_dynamic_data_provider!(HelloWorldProvider, [HelloWorldV1Marker,], AnyMarker);
-#[cfg(feature = "datagen")]
-make_exportable_provider!(HelloWorldProvider, [HelloWorldV1Marker,]);
-
+#[cfg(feature = "deserialize_json")]
/// A data provider returning Hello World strings in different languages as JSON blobs.
///
/// Mostly useful for testing.
@@ -157,9 +157,11 @@ make_exportable_provider!(HelloWorldProvider, [HelloWorldV1Marker,]);
/// .take_payload()
/// .expect("Data should be present");
///
-/// assert_eq!(b"{\"message\":\"Hallo Welt\"}", german_hello_world.get());
-pub struct HelloWorldJsonProvider(HelloWorldProvider);
+/// assert_eq!(german_hello_world.get(), br#"{"message":"Hallo Welt"}"#);
+#[derive(Debug)]
+pub struct HelloWorldJsonProvider;
+#[cfg(feature = "deserialize_json")]
impl BufferProvider for HelloWorldJsonProvider {
fn load_buffer(
&self,
@@ -167,23 +169,38 @@ impl BufferProvider for HelloWorldJsonProvider {
req: DataRequest,
) -> Result<DataResponse<BufferMarker>, DataError> {
key.match_key(HelloWorldV1Marker::KEY)?;
- let result = self.0.load(req)?;
+ let result = HelloWorldProvider.load(req)?;
let (mut metadata, old_payload) =
DataResponse::<HelloWorldV1Marker>::take_metadata_and_payload(result)?;
- metadata.buffer_format = Some(BufferFormat::Json);
- let mut buffer = String::new();
- buffer.push_str("{\"message\":\"");
- helpers::escape_for_json(&old_payload.get().message, &mut buffer);
- buffer.push_str("\"}");
+ metadata.buffer_format = Some(crate::buf::BufferFormat::Json);
+ #[allow(clippy::unwrap_used)] // HelloWorldV1::serialize is infallible
Ok(DataResponse {
metadata,
payload: Some(DataPayload::from_owned_buffer(
- buffer.into_bytes().into_boxed_slice(),
+ serde_json::to_string(old_payload.get())
+ .unwrap()
+ .into_bytes()
+ .into_boxed_slice(),
)),
})
}
}
+#[cfg(feature = "datagen")]
+impl IterableDataProvider<HelloWorldV1Marker> for HelloWorldProvider {
+ fn supported_locales(&self) -> Result<Vec<DataLocale>, DataError> {
+ #[allow(clippy::unwrap_used)] // datagen
+ Ok(Self::DATA
+ .iter()
+ .map(|(s, _)| s.parse::<icu_locid::LanguageIdentifier>().unwrap())
+ .map(DataLocale::from)
+ .collect())
+ }
+}
+
+#[cfg(feature = "datagen")]
+make_exportable_provider!(HelloWorldProvider, [HelloWorldV1Marker,]);
+
/// A type that formats localized "hello world" strings.
///
/// This type is intended to take the shape of a typical ICU4X formatter API.
@@ -203,6 +220,7 @@ impl BufferProvider for HelloWorldJsonProvider {
///
/// assert_writeable_eq!(fmt.format(), "Saluton, Mondo");
/// ```
+#[derive(Debug)]
pub struct HelloWorldFormatter {
data: DataPayload<HelloWorldV1Marker>,
}
@@ -210,6 +228,7 @@ pub struct HelloWorldFormatter {
/// A formatted hello world message. Implements [`Writeable`].
///
/// For an example, see [`HelloWorldFormatter`].
+#[derive(Debug)]
pub struct FormattedHelloWorld<'l> {
data: &'l HelloWorldV1<'l>,
}
@@ -269,18 +288,6 @@ impl<'l> Writeable for FormattedHelloWorld<'l> {
writeable::impl_display_with_writeable!(FormattedHelloWorld<'_>);
#[cfg(feature = "datagen")]
-impl IterableDataProvider<HelloWorldV1Marker> for HelloWorldProvider {
- fn supported_locales(&self) -> Result<Vec<DataLocale>, DataError> {
- #[allow(clippy::unwrap_used)] // datagen
- Ok(Self::DATA
- .iter()
- .map(|(s, _)| s.parse::<icu_locid::LanguageIdentifier>().unwrap())
- .map(DataLocale::from)
- .collect())
- }
-}
-
-#[cfg(feature = "datagen")]
#[test]
fn test_iter() {
use icu_locid::locale;
diff --git a/vendor/icu_provider/src/helpers.rs b/vendor/icu_provider/src/helpers.rs
index 8d499f7ef..998e656da 100644
--- a/vendor/icu_provider/src/helpers.rs
+++ b/vendor/icu_provider/src/helpers.rs
@@ -4,79 +4,6 @@
//! Internal helper functions.
-use alloc::string::String;
-
-/// Prints a JSON-safe string to the output.
-pub fn escape_for_json<'o>(input: &str, output: &'o mut String) -> &'o mut String {
- // From the ECMA-404 specification:
- // "A string is a sequence of Unicode code points wrapped with quotation marks (U+0022).
- // All code points may be placed within the quotation marks except for the code points
- // that must be escaped: quotation mark (U+0022), reverse solidus (U+005C), and the
- // control characters U+0000 to U+001F. There are two-character escape sequence
- // representations of some characters."
- for cp in input.chars() {
- let str_to_append = match cp {
- '\u{0000}' => "\\u0000",
- '\u{0001}' => "\\u0001",
- '\u{0002}' => "\\u0002",
- '\u{0003}' => "\\u0003",
- '\u{0004}' => "\\u0004",
- '\u{0005}' => "\\u0005",
- '\u{0006}' => "\\u0006",
- '\u{0007}' => "\\u0007",
- '\u{0008}' => "\\b",
- '\u{0009}' => "\\t",
- '\u{000A}' => "\\n",
- '\u{000B}' => "\\u000B",
- '\u{000C}' => "\\f",
- '\u{000D}' => "\\r",
- '\u{000E}' => "\\u000E",
- '\u{000F}' => "\\u000F",
- '\u{0010}' => "\\u0010",
- '\u{0011}' => "\\u0011",
- '\u{0012}' => "\\u0012",
- '\u{0013}' => "\\u0013",
- '\u{0014}' => "\\u0014",
- '\u{0015}' => "\\u0015",
- '\u{0016}' => "\\u0016",
- '\u{0017}' => "\\u0017",
- '\u{0018}' => "\\u0018",
- '\u{0019}' => "\\u0019",
- '\u{001A}' => "\\u001A",
- '\u{001B}' => "\\u001B",
- '\u{001C}' => "\\u001C",
- '\u{001D}' => "\\u001D",
- '\u{001E}' => "\\u001E",
- '\u{001F}' => "\\u001F",
- '\u{0022}' => "\\\"",
- '\u{005C}' => "\\\\",
- cp => {
- output.push(cp);
- continue;
- }
- };
- output.push_str(str_to_append);
- }
- output
-}
-
-#[test]
-fn test_escape_for_json() {
- assert_eq!("", escape_for_json("", &mut String::new()));
- assert_eq!("abc", escape_for_json("abc", &mut String::new()));
- assert_eq!("ab\\nc", escape_for_json("ab\nc", &mut String::new()));
- assert_eq!("ab\\\\c", escape_for_json("ab\\c", &mut String::new()));
- assert_eq!("ab\\\"c", escape_for_json("ab\"c", &mut String::new()));
- assert_eq!(
- "ab\\u0000c",
- escape_for_json("ab\u{0000}c", &mut String::new())
- );
- assert_eq!(
- "ab\\u001Fc",
- escape_for_json("ab\u{001F}c", &mut String::new())
- );
-}
-
/// Const function to compute the FxHash of a byte array with little-endian byte order.
///
/// FxHash is a speedy hash algorithm used within rustc. The algorithm is satisfactory for our
@@ -248,7 +175,22 @@ macro_rules! gen_any_buffer_constructors {
}
};
- (locale: skip, $options_arg:ident: $options_ty:path, error: $error_ty:path) => {
+
+ (locale: skip, options: skip, result: $result_ty:path, functions: [$f1:path, $f2:ident, $f3:ident]) => {
+ #[doc = $crate::gen_any_buffer_docs!(ANY, $crate, $f1)]
+ pub fn $f2(provider: &(impl $crate::AnyProvider + ?Sized)) -> $result_ty {
+ use $crate::AsDowncastingAnyProvider;
+ $f1(&provider.as_downcasting())
+ }
+ #[cfg(feature = "serde")]
+ #[doc = $crate::gen_any_buffer_docs!(BUFFER, $crate, $f1)]
+ pub fn $f3(provider: &(impl $crate::BufferProvider + ?Sized)) -> $result_ty {
+ use $crate::AsDeserializingBufferProvider;
+ $f1(&provider.as_deserializing())
+ }
+ };
+
+ (locale: skip, $options_arg:ident: $options_ty:ty, error: $error_ty:path) => {
$crate::gen_any_buffer_constructors!(
locale: skip,
$options_arg: $options_ty,
@@ -260,34 +202,32 @@ macro_rules! gen_any_buffer_constructors {
]
);
};
- (locale: skip, $options_arg:ident: $options_ty:path, error: $error_ty:path, functions: [$f1:path, $f2:ident, $f3:ident]) => {
+ (locale: skip, $options_arg:ident: $options_ty:ty, result: $result_ty:ty, functions: [$f1:path, $f2:ident, $f3:ident]) => {
#[doc = $crate::gen_any_buffer_docs!(ANY, $crate, $f1)]
- pub fn $f2(provider: &(impl $crate::AnyProvider + ?Sized), $options_arg: $options_ty) -> Result<Self, $error_ty> {
+ pub fn $f2(provider: &(impl $crate::AnyProvider + ?Sized), $options_arg: $options_ty) -> $result_ty {
use $crate::AsDowncastingAnyProvider;
$f1(&provider.as_downcasting(), $options_arg)
}
#[cfg(feature = "serde")]
#[doc = $crate::gen_any_buffer_docs!(BUFFER, $crate, $f1)]
- pub fn $f3(provider: &(impl $crate::BufferProvider + ?Sized), $options_arg: $options_ty) -> Result<Self, $error_ty> {
+ pub fn $f3(provider: &(impl $crate::BufferProvider + ?Sized), $options_arg: $options_ty) -> $result_ty {
use $crate::AsDeserializingBufferProvider;
$f1(&provider.as_deserializing(), $options_arg)
}
};
-
- (locale: skip, options: skip, result: $result_ty:path, functions: [$f1:path, $f2:ident, $f3:ident]) => {
+ (locale: skip, $options_arg:ident: $options_ty:ty, error: $error_ty:ty, functions: [$f1:path, $f2:ident, $f3:ident]) => {
#[doc = $crate::gen_any_buffer_docs!(ANY, $crate, $f1)]
- pub fn $f2(provider: &(impl $crate::AnyProvider + ?Sized)) -> $result_ty {
+ pub fn $f2(provider: &(impl $crate::AnyProvider + ?Sized), $options_arg: $options_ty) -> Result<Self, $error_ty> {
use $crate::AsDowncastingAnyProvider;
- $f1(&provider.as_downcasting())
+ $f1(&provider.as_downcasting(), $options_arg)
}
#[cfg(feature = "serde")]
#[doc = $crate::gen_any_buffer_docs!(BUFFER, $crate, $f1)]
- pub fn $f3(provider: &(impl $crate::BufferProvider + ?Sized)) -> $result_ty {
+ pub fn $f3(provider: &(impl $crate::BufferProvider + ?Sized), $options_arg: $options_ty) -> Result<Self, $error_ty> {
use $crate::AsDeserializingBufferProvider;
- $f1(&provider.as_deserializing())
+ $f1(&provider.as_deserializing(), $options_arg)
}
};
-
(locale: include, options: skip, error: $error_ty:path) => {
$crate::gen_any_buffer_constructors!(
locale: include,
diff --git a/vendor/icu_provider/src/key.rs b/vendor/icu_provider/src/key.rs
index d4d6905c9..8c76608fc 100644
--- a/vendor/icu_provider/src/key.rs
+++ b/vendor/icu_provider/src/key.rs
@@ -210,20 +210,20 @@ impl Default for DataKeyMetadata {
/// Therefore, users should not generally create DataKey instances; they should instead use
/// the ones exported by a component.
///
-/// `DataKey`s are created with the [`data_key!`] macro:
+/// `DataKey`s are created with the [`data_key!`](crate::data_key) macro:
///
/// ```
-/// # use icu_provider::prelude::DataKey;
+/// # use icu_provider::DataKey;
/// const K: DataKey = icu_provider::data_key!("foo/bar@1");
/// ```
///
/// The human-readable path string ends with `@` followed by one or more digits (the version
/// number). Paths do not contain characters other than ASCII letters and digits, `_`, `/`.
///
-/// Invalid paths are compile-time errors (as [`data_key!`] uses `const`).
+/// Invalid paths are compile-time errors (as [`data_key!`](crate::data_key) uses `const`).
///
/// ```compile_fail,E0080
-/// # use icu_provider::prelude::DataKey;
+/// # use icu_provider::DataKey;
/// const K: DataKey = icu_provider::data_key!("foo/../bar@1");
/// ```
#[derive(Copy, Clone)]
diff --git a/vendor/icu_provider/src/lib.rs b/vendor/icu_provider/src/lib.rs
index 7ee5b34e2..86c2001cd 100644
--- a/vendor/icu_provider/src/lib.rs
+++ b/vendor/icu_provider/src/lib.rs
@@ -54,8 +54,7 @@
//!
//! Examples of AnyProviders:
//!
-//! - [`CldrJsonDataProvider`] reads structured data from CLDR JSON source files and returns
-//! structured Rust objects.
+//! - [`DatagenProvider`] reads structured data from CLDR source files and returns ICU4X data structs.
//! - [`AnyPayloadProvider`] wraps a specific data struct and returns it.
//! - The `BakedDataProvider` which encodes structured data directly in Rust source
//!
@@ -77,7 +76,7 @@
//!
//! ## Testing Provider
//!
-//! This crate also contains a concrete provider for testing purposes:
+//! This crate also contains a concrete provider for demonstration purposes:
//!
//! - [`HelloWorldProvider`] returns "hello world" strings in several languages.
//!
@@ -111,6 +110,7 @@
//! [`Yokeable`]: yoke::Yokeable
//! [`impl_dynamic_data_provider!`]: impl_dynamic_data_provider
//! [`icu_provider_adapters`]: ../icu_provider_adapters/index.html
+//! [`DatagenProvider`]: ../icu_datagen/struct.DatagenProvider.html
//! [`as_downcasting()`]: AsDowncastingAnyProvider::as_downcasting
//! [`as_deserializing()`]: AsDeserializingBufferProvider::as_deserializing
//! [`CldrJsonDataProvider`]: ../icu_datagen/cldr/struct.CldrJsonDataProvider.html
@@ -130,83 +130,128 @@
clippy::panic,
clippy::exhaustive_structs,
clippy::exhaustive_enums,
- // TODO(#2266): enable missing_debug_implementations,
+ missing_debug_implementations,
)
)]
#![warn(missing_docs)]
extern crate alloc;
+mod data_provider;
+mod error;
+mod helpers;
+mod key;
+mod request;
+mod response;
+
pub mod any;
pub mod buf;
pub mod constructors;
-mod data_provider;
#[cfg(feature = "datagen")]
#[macro_use]
pub mod datagen;
#[macro_use]
pub mod dynutil;
-mod error;
pub mod hello_world;
-mod helpers;
#[macro_use]
-mod key;
pub mod marker;
-mod request;
-mod response;
#[cfg(feature = "serde")]
pub mod serde;
+// Types from private modules
+pub use crate::data_provider::DataProvider;
+pub use crate::data_provider::DynamicDataProvider;
+pub use crate::error::DataError;
+pub use crate::error::DataErrorKind;
+pub use crate::key::DataKey;
+pub use crate::key::DataKeyHash;
+pub use crate::key::DataKeyMetadata;
+pub use crate::key::DataKeyPath;
+pub use crate::key::FallbackPriority;
+pub use crate::key::FallbackSupplement;
+pub use crate::request::DataLocale;
+pub use crate::request::DataRequest;
+pub use crate::request::DataRequestMetadata;
+pub use crate::response::Cart;
+pub use crate::response::DataPayload;
+pub use crate::response::DataResponse;
+pub use crate::response::DataResponseMetadata;
#[cfg(feature = "macros")]
pub use icu_provider_macros::data_struct;
+// Reexports from public modules
+pub use crate::any::AnyMarker;
+pub use crate::any::AnyPayload;
+pub use crate::any::AnyProvider;
+pub use crate::any::AnyResponse;
+pub use crate::any::AsDowncastingAnyProvider;
+pub use crate::any::AsDynamicDataProviderAnyMarkerWrap;
+pub use crate::any::MaybeSendSync;
+pub use crate::buf::BufferMarker;
+pub use crate::buf::BufferProvider;
+pub use crate::marker::DataMarker;
+pub use crate::marker::KeyedDataMarker;
+#[cfg(feature = "serde")]
+pub use crate::serde::AsDeserializingBufferProvider;
+
+/// Core selection of APIs and structures for the ICU4X data provider.
pub mod prelude {
- //! Core selection of APIs and structures for the ICU4X data provider.
- pub use crate::any::AnyMarker;
- pub use crate::any::AnyPayload;
- pub use crate::any::AnyProvider;
- pub use crate::any::AnyResponse;
- pub use crate::buf::BufferMarker;
- pub use crate::buf::BufferProvider;
+ #[doc(no_inline)]
pub use crate::data_key;
- pub use crate::data_provider::DataProvider;
- pub use crate::data_provider::DynamicDataProvider;
- pub use crate::error::DataError;
- pub use crate::error::DataErrorKind;
- pub use crate::key::DataKey;
- pub use crate::key::DataKeyHash;
- pub use crate::marker::DataMarker;
- pub use crate::marker::KeyedDataMarker;
- pub use crate::request::DataLocale;
- pub use crate::request::DataRequest;
- pub use crate::response::DataPayload;
- pub use crate::response::DataResponse;
- pub use crate::response::DataResponseMetadata;
-
- pub use crate::any::AsDowncastingAnyProvider;
- pub use crate::any::AsDynamicDataProviderAnyMarkerWrap;
+ #[doc(no_inline)]
+ pub use crate::AnyMarker;
+ #[doc(no_inline)]
+ pub use crate::AnyPayload;
+ #[doc(no_inline)]
+ pub use crate::AnyProvider;
+ #[doc(no_inline)]
+ pub use crate::AnyResponse;
+ #[doc(no_inline)]
#[cfg(feature = "serde")]
- pub use crate::serde::AsDeserializingBufferProvider;
+ pub use crate::AsDeserializingBufferProvider;
+ #[doc(no_inline)]
+ pub use crate::AsDowncastingAnyProvider;
+ #[doc(no_inline)]
+ pub use crate::AsDynamicDataProviderAnyMarkerWrap;
+ #[doc(no_inline)]
+ pub use crate::BufferMarker;
+ #[doc(no_inline)]
+ pub use crate::BufferProvider;
+ #[doc(no_inline)]
+ pub use crate::DataError;
+ #[doc(no_inline)]
+ pub use crate::DataErrorKind;
+ #[doc(no_inline)]
+ pub use crate::DataKey;
+ #[doc(no_inline)]
+ pub use crate::DataKeyHash;
+ #[doc(no_inline)]
+ pub use crate::DataLocale;
+ #[doc(no_inline)]
+ pub use crate::DataMarker;
+ #[doc(no_inline)]
+ pub use crate::DataPayload;
+ #[doc(no_inline)]
+ pub use crate::DataProvider;
+ #[doc(no_inline)]
+ pub use crate::DataRequest;
+ #[doc(no_inline)]
+ pub use crate::DataRequestMetadata;
+ #[doc(no_inline)]
+ pub use crate::DataResponse;
+ #[doc(no_inline)]
+ pub use crate::DataResponseMetadata;
+ #[doc(no_inline)]
+ pub use crate::DynamicDataProvider;
+ #[doc(no_inline)]
+ pub use crate::KeyedDataMarker;
- /// Re-export of the yoke and zerofrom crates for convenience of downstream implementors.
#[doc(hidden)]
pub use yoke;
#[doc(hidden)]
pub use zerofrom;
}
-// Also include the same symbols at the top level for selective inclusion
-pub use prelude::*;
-
-// Less important non-prelude items
-pub use crate::any::MaybeSendSync;
-pub use crate::key::DataKeyMetadata;
-pub use crate::key::DataKeyPath;
-pub use crate::key::FallbackPriority;
-pub use crate::key::FallbackSupplement;
-pub use crate::request::DataRequestMetadata;
-pub use crate::response::Cart;
-
// For macros
#[doc(hidden)]
pub mod _internal {
diff --git a/vendor/icu_provider/src/marker.rs b/vendor/icu_provider/src/marker.rs
index 870885797..0065bb656 100644
--- a/vendor/icu_provider/src/marker.rs
+++ b/vendor/icu_provider/src/marker.rs
@@ -5,7 +5,7 @@
//! Marker types and traits for DataProvider.
use crate::key::DataKey;
-use crate::yoke::Yokeable;
+use yoke::Yokeable;
/// Trait marker for data structs. All types delivered by the data provider must be associated with
/// something implementing this trait.
@@ -22,18 +22,20 @@ use crate::yoke::Yokeable;
///
/// Also see [`KeyedDataMarker`].
///
+/// Note: `DataMarker`s are quasi-const-generic compile-time objects, and as such are expected
+/// to be unit structs. As this is not something that can be enforced by the type system, we
+/// currently only have a `'static` bound on them (which is needed by a lot of our code).
+///
/// # Examples
///
/// Manually implementing DataMarker for a custom type:
///
/// ```
/// use icu_provider::prelude::*;
-/// use icu_provider::yoke::*;
-/// use icu_provider::zerofrom::*;
/// use std::borrow::Cow;
/// use std::rc::Rc;
///
-/// #[derive(Yokeable, ZeroFrom)]
+/// #[derive(yoke::Yokeable, zerofrom::ZeroFrom)]
/// struct MyDataStruct<'data> {
/// message: Cow<'data, str>,
/// }
@@ -53,7 +55,7 @@ use crate::yoke::Yokeable;
/// ```
///
/// [`data_struct`]: crate::data_struct
-pub trait DataMarker {
+pub trait DataMarker: 'static {
/// A type that implements [`Yokeable`]. This should typically be the `'static` version of a
/// data struct.
type Yokeable: for<'a> Yokeable<'a>;
@@ -70,6 +72,10 @@ pub trait DataMarker {
/// [`BufferMarker`] and [`AnyMarker`] are examples of markers that do _not_ implement this trait
/// because they are not specific to a single key.
///
+/// Note: `KeyedDataMarker`s are quasi-const-generic compile-time objects, and as such are expected
+/// to be unit structs. As this is not something that can be enforced by the type system, we
+/// currently only have a `'static` bound on them (which is needed by a lot of our code).
+///
/// [`data_struct!`]: crate::data_struct
/// [`DataProvider`]: crate::DataProvider
/// [`BufferMarker`]: crate::BufferMarker
diff --git a/vendor/icu_provider/src/request.rs b/vendor/icu_provider/src/request.rs
index 5f51f3a2c..c5bdbe84b 100644
--- a/vendor/icu_provider/src/request.rs
+++ b/vendor/icu_provider/src/request.rs
@@ -37,7 +37,10 @@ impl fmt::Display for DataRequest<'_> {
/// for tuning locale fallback, buffer layout, and so forth.
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[non_exhaustive]
-pub struct DataRequestMetadata;
+pub struct DataRequestMetadata {
+ /// Silent requests do not log errors. This can be used for exploratory querying, such as fallbacks.
+ pub silent: bool,
+}
/// The main locale type used by the ICU4X data provider.
///
@@ -120,7 +123,7 @@ impl<'a> Default for &'a DataLocale {
impl fmt::Debug for DataLocale {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "DataLocale{{{}}}", self)
+ write!(f, "DataLocale{{{self}}}")
}
}
diff --git a/vendor/icu_provider/src/response.rs b/vendor/icu_provider/src/response.rs
index 1ea6c8a76..ad0c5865f 100644
--- a/vendor/icu_provider/src/response.rs
+++ b/vendor/icu_provider/src/response.rs
@@ -6,13 +6,13 @@ use crate::buf::BufferMarker;
use crate::error::{DataError, DataErrorKind};
use crate::marker::DataMarker;
use crate::request::DataLocale;
-use crate::yoke::trait_hack::YokeTraitHack;
-use crate::yoke::*;
use alloc::boxed::Box;
use core::convert::TryFrom;
use core::fmt::Debug;
use core::marker::PhantomData;
use core::ops::Deref;
+use yoke::trait_hack::YokeTraitHack;
+use yoke::*;
#[cfg(not(feature = "sync"))]
use alloc::rc::Rc as SelectedRc;
@@ -79,14 +79,14 @@ where
}
/// The type of the "cart" that is used by `DataPayload`.
-#[derive(Clone)]
+#[derive(Clone, Debug)]
#[allow(clippy::redundant_allocation)] // false positive, it's cheaper to wrap an existing Box in an Rc than to reallocate a huge Rc
pub struct Cart(SelectedRc<Box<[u8]>>);
impl Deref for Cart {
type Target = Box<[u8]>;
fn deref(&self) -> &Self::Target {
- &*self.0
+ &self.0
}
}
// Safe because both Rc and Arc are StableDeref, and our impl delegates.
@@ -95,13 +95,13 @@ unsafe impl stable_deref_trait::StableDeref for Cart {}
unsafe impl yoke::CloneableCart for Cart {}
impl Cart {
- /// Creates a Yoke<Y, Option<Cart>> from owned bytes by applying f.
+ /// Creates a `Yoke<Y, Option<Cart>>` from owned bytes by applying `f`.
pub fn try_make_yoke<Y, F, E>(cart: Box<[u8]>, f: F) -> Result<Yoke<Y, Option<Self>>, E>
where
for<'a> Y: Yokeable<'a>,
F: FnOnce(&[u8]) -> Result<<Y as Yokeable>::Output, E>,
{
- Yoke::try_attach_to_cart(SelectedRc::new(cart), |b| f(&*b))
+ Yoke::try_attach_to_cart(SelectedRc::new(cart), |b| f(b))
// Safe because the cart is only wrapped
.map(|yoke| unsafe { yoke.replace_cart(Cart) })
.map(Yoke::wrap_cart_in_option)
@@ -631,5 +631,5 @@ fn test_debug() {
message: Cow::Borrowed("foo"),
})),
};
- assert_eq!("DataResponse { metadata: DataResponseMetadata { locale: None, buffer_format: None }, payload: Some(HelloWorldV1 { message: \"foo\" }) }", format!("{:?}", resp));
+ assert_eq!("DataResponse { metadata: DataResponseMetadata { locale: None, buffer_format: None }, payload: Some(HelloWorldV1 { message: \"foo\" }) }", format!("{resp:?}"));
}
diff --git a/vendor/icu_provider/src/serde/borrow_de_utils.rs b/vendor/icu_provider/src/serde/borrow_de_utils.rs
index afce7641e..d614bc9ec 100644
--- a/vendor/icu_provider/src/serde/borrow_de_utils.rs
+++ b/vendor/icu_provider/src/serde/borrow_de_utils.rs
@@ -10,12 +10,14 @@ use serde::Deserialize;
#[serde(transparent)]
// Cows fail to borrow in some situations (array, option), but structs of Cows don't.
#[allow(clippy::exhaustive_structs)] // newtype
+#[derive(Debug)]
pub struct CowWrap<'data>(#[serde(borrow)] pub Cow<'data, str>);
#[derive(Deserialize)]
#[serde(transparent)]
// Cows fail to borrow in some situations (array, option), but structs of Cows don't.
#[allow(clippy::exhaustive_structs)] // newtype
+#[derive(Debug)]
pub struct CowBytesWrap<'data>(#[serde(borrow)] pub Cow<'data, [u8]>);
pub fn array_of_cow<'de, D, const N: usize>(deserializer: D) -> Result<[Cow<'de, str>; N], D::Error>
diff --git a/vendor/icu_provider/src/serde/mod.rs b/vendor/icu_provider/src/serde/mod.rs
index 2e96b3cb3..098f1e880 100644
--- a/vendor/icu_provider/src/serde/mod.rs
+++ b/vendor/icu_provider/src/serde/mod.rs
@@ -23,6 +23,7 @@ use yoke::trait_hack::YokeTraitHack;
use yoke::Yokeable;
/// A [`BufferProvider`] that deserializes its data using Serde.
+#[derive(Debug)]
pub struct DeserializingBufferProvider<'a, P: ?Sized>(&'a P);
/// Blanket-implemented trait adding the [`Self::as_deserializing()`] function.
@@ -101,7 +102,7 @@ impl DataPayload<BufferMarker> {
/// use icu_provider::hello_world::*;
/// use icu_provider::prelude::*;
///
- /// let buffer: &[u8] = b"{\"message\":\"Hallo Welt\"}";
+ /// let buffer: &[u8] = br#"{"message":"Hallo Welt"}"#;
///
/// let buffer_payload = DataPayload::from_owned(buffer);
/// let payload: DataPayload<HelloWorldV1Marker> = buffer_payload