Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Feb 26, 2025
1 parent c7820c8 commit ef275d8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion documents/design/data_pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ icu_provider::data_marker!(
);

/// This is a sample data struct.
#[derive(Debug, PartialEq, Clone, yoke::Yokeable, zerofrom::ZeroFrom)]
#[derive(Debug, PartialEq, Clone, yoke::Yokeable)]
#[cfg_attr(feature = "serde", derive(Deserialize))]
#[cfg_attr(feature = "datagen", derive(Serialize))]
pub struct SampleDataStruct<'data> {
Expand Down
2 changes: 1 addition & 1 deletion documents/process/writing_a_new_data_struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ icu_provider::data_marker!(
DecimalSymbols<'static>,
);

#[derive(Debug, PartialEq, Clone, yoke::Yokeable, zerofrom::ZeroFrom)]
#[derive(Debug, PartialEq, Clone, yoke::Yokeable)]
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
#[cfg_attr(feature = "datagen", databake(path = icu_decimal::provider))]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
Expand Down
2 changes: 1 addition & 1 deletion provider/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use zerovec::ule::*;
/// use icu_provider::prelude::*;
/// use std::borrow::Cow;
///
/// #[derive(yoke::Yokeable, zerofrom::ZeroFrom)]
/// #[derive(yoke::Yokeable)]
/// struct MyDataStruct<'data> {
/// message: Cow<'data, str>,
/// }
Expand Down
13 changes: 7 additions & 6 deletions tutorials/data_provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ use std::borrow::{Borrow, Cow};
use std::convert::TryInto;
use std::sync::Mutex;
use yoke::Yokeable;
use zerofrom::ZeroFrom;

/// A data provider that caches response payloads in an LRU cache.
pub struct LruDataCache<P> {
Expand All @@ -106,7 +105,6 @@ impl<'a> Borrow<CacheKey<'a>> for lru::KeyRef<CacheKeyWrap> {
impl<M, P> DataProvider<M> for LruDataCache<P>
where
M: DataMarker,
M::DataStruct: ZeroFrom<'static, M::DataStruct>,
for<'a> <M::DataStruct as Yokeable<'a>>::Output: Clone,
P: DataProvider<M>,
{
Expand Down Expand Up @@ -198,7 +196,7 @@ The following example illustrates how to overwrite the decimal separators for a
```rust
use core::any::Any;
use icu::decimal::DecimalFormatter;
use icu::decimal::provider::{DecimalSymbolsV2, DecimalSymbolStrsBuilder};
use icu::decimal::provider::{DecimalSymbols, DecimalSymbolsV2, DecimalSymbolStrsBuilder};
use icu_provider::prelude::*;
use icu_provider_adapters::fixed::FixedProvider;
use icu::locale::locale;
Expand All @@ -218,11 +216,14 @@ where
let mut res = self.0.load(req)?;
if req.id.locale.region == Some(region!("CH")) {
if let Ok(mut decimal_payload) = res.payload.dynamic_cast_mut::<DecimalSymbolsV2>() {
decimal_payload.with_mut(|data| {
*decimal_payload = decimal_payload.map_project_cloned::<DecimalSymbolsV2, _>(|data, _| {
let mut builder = DecimalSymbolStrsBuilder::from(&*data.strings);
// Change grouping separator for all Swiss locales to '🐮'
builder.grouping_separator = VarZeroCow::new_owned("🐮".into());
data.strings = builder.build();
DecimalSymbols {
strings: builder.build(),
..data.clone()
}
});
}
}
Expand Down Expand Up @@ -279,7 +280,7 @@ use std::collections::BTreeSet;

icu_provider::data_marker!(CustomV1, Custom<'static>);

#[derive(Debug, PartialEq, serde::Deserialize, serde::Serialize, databake::Bake, yoke::Yokeable, zerofrom::ZeroFrom)]
#[derive(Debug, PartialEq, serde::Deserialize, serde::Serialize, databake::Bake, yoke::Yokeable)]
#[databake(path = crate)]
pub struct Custom<'data> {
message: Cow<'data, str>,
Expand Down

0 comments on commit ef275d8

Please sign in to comment.