Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving AuxiliaryKeys to DataRequest as DataKeyAttributes #4981

Merged
merged 27 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions components/calendar/src/week_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl WeekCalculator {
&provider.as_downcasting(),
DataRequest {
locale,
metadata: Default::default(),
..Default::default()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought: using ..Default::default() means that if we ever refactor DataRequest again, we won't get compiler errors for missing fields, which I think was an important part of building this PR.

Copy link
Member Author

@robertbastian robertbastian May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't really need or use that. Searching for DataRequest { is exhaustive because there are no constructors.

},
)
.and_then(DataResponse::take_payload)
Expand All @@ -86,7 +86,7 @@ impl WeekCalculator {
&provider.as_deserializing(),
DataRequest {
locale,
metadata: Default::default(),
..Default::default()
},
)
.and_then(DataResponse::take_payload)
Expand All @@ -103,7 +103,7 @@ impl WeekCalculator {
provider
.load(DataRequest {
locale,
metadata: Default::default(),
..Default::default()
})
.and_then(DataResponse::take_payload)
.map(|payload| WeekCalculator {
Expand Down
2 changes: 1 addition & 1 deletion components/collator/src/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Collator {
{
let req = DataRequest {
locale,
metadata: Default::default(),
..Default::default()
};

let metadata_payload: DataPayload<crate::provider::CollationMetadataV1Marker> =
Expand Down
6 changes: 3 additions & 3 deletions components/collator/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ fn test_nb_nn_no() {
&icu_collator::provider::Baked,
DataRequest {
locale: &locale,
metadata: Default::default()
..Default::default()
}
)
.unwrap()
Expand All @@ -1212,7 +1212,7 @@ fn test_nb_nn_no() {
&icu_collator::provider::Baked,
DataRequest {
locale: &locale,
metadata: Default::default()
..Default::default()
}
)
.unwrap()
Expand All @@ -1232,7 +1232,7 @@ fn test_nb_nn_no() {
&icu_collator::provider::Baked,
DataRequest {
locale: &locale,
metadata: Default::default()
..Default::default()
}
)
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ icu_calendar = { workspace = true }
icu_decimal = { workspace = true }
icu_locale_core = { workspace = true }
icu_plurals = { workspace = true }
icu_provider = { workspace = true, features = ["macros", "experimental"] }
icu_provider = { workspace = true, features = ["macros"] }
icu_timezone = { workspace = true }
smallvec = { workspace = true }
tinystr = { workspace = true, features = ["alloc", "zerovec"] }
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/any/zoned_datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use icu_decimal::provider::DecimalSymbolsV1Marker;
use icu_plurals::provider::OrdinalV1Marker;
use writeable::Writeable;

size_test!(ZonedDateTimeFormatter, zoned_date_time_formatter_size, 6248);
size_test!(ZonedDateTimeFormatter, zoned_date_time_formatter_size, 6224);

/// [`ZonedDateTimeFormatter`] is a formatter capable of formatting
/// date/times with time zones from any calendar, selected at runtime. For the difference between this and [`TypedZonedDateTimeFormatter`](crate::TypedZonedDateTimeFormatter),
Expand Down
8 changes: 4 additions & 4 deletions components/datetime/src/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ where
let payload = provider
.load(DataRequest {
locale,
metadata: Default::default(),
..Default::default()
})?
.take_payload()?;
Ok(payload.cast())
Expand All @@ -404,7 +404,7 @@ where
let payload = provider
.load(DataRequest {
locale,
metadata: Default::default(),
..Default::default()
})?
.take_payload()?;
Ok(payload.cast())
Expand Down Expand Up @@ -433,7 +433,7 @@ where
{
let req = DataRequest {
locale,
metadata: Default::default(),
..Default::default()
};
let payload = match kind {
AnyCalendarKind::Buddhist => {
Expand Down Expand Up @@ -554,7 +554,7 @@ where
{
let req = DataRequest {
locale,
metadata: Default::default(),
..Default::default()
};
let payload = match kind {
AnyCalendarKind::Buddhist => {
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/format/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ mod tests {
let locale = "en-u-ca-gregory".parse().unwrap();
let req = DataRequest {
locale: &locale,
metadata: Default::default(),
..Default::default()
};
let date_data: DataPayload<GregorianDateSymbolsV1Marker> = crate::provider::Baked
.load(req)
Expand Down
112 changes: 55 additions & 57 deletions components/datetime/src/format/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<M: DataMarker> BoundDataProvider<M> for PhantomProvider {
size_test!(
TypedDateTimeNames<icu_calendar::Gregorian, DateTimeMarker>,
typed_date_time_names_size,
488
464
);

/// A low-level type that formats datetime patterns with localized symbols.
Expand Down Expand Up @@ -925,20 +925,19 @@ impl<R: DateTimeNamesMarker> RawDateTimeNames<R> {
NamePresence::NotLoaded => (),
NamePresence::Mismatched => return Err(SingleLoadError::DuplicateField(field)),
};
let mut locale = locale.clone();
locale.set_aux(AuxiliaryKeys::from_subtag(aux::symbol_subtag_for(
aux::Context::Format,
match field_length {
FieldLength::Abbreviated => aux::Length::Abbr,
FieldLength::Narrow => aux::Length::Narrow,
FieldLength::Wide => aux::Length::Wide,
_ => return Err(SingleLoadError::UnsupportedField(field)),
},
)));
let payload = provider
.load_bound(DataRequest {
locale: &locale,
metadata: Default::default(),
locale,
key_attributes: &DataKeyAttributes::from_tinystr(key_attrs::symbol_attr_for(
key_attrs::Context::Format,
match field_length {
FieldLength::Abbreviated => key_attrs::Length::Abbr,
FieldLength::Narrow => key_attrs::Length::Narrow,
FieldLength::Wide => key_attrs::Length::Wide,
_ => return Err(SingleLoadError::UnsupportedField(field)),
},
)),
..Default::default()
})
.and_then(DataResponse::take_payload)
.map_err(SingleLoadError::Data)?;
Expand Down Expand Up @@ -974,23 +973,22 @@ impl<R: DateTimeNamesMarker> RawDateTimeNames<R> {
NamePresence::NotLoaded => (),
NamePresence::Mismatched => return Err(SingleLoadError::DuplicateField(field)),
};
let mut locale = locale.clone();
locale.set_aux(AuxiliaryKeys::from_subtag(aux::symbol_subtag_for(
match field_symbol {
fields::Month::Format => aux::Context::Format,
fields::Month::StandAlone => aux::Context::Standalone,
},
match field_length {
FieldLength::Abbreviated => aux::Length::Abbr,
FieldLength::Narrow => aux::Length::Narrow,
FieldLength::Wide => aux::Length::Wide,
_ => return Err(SingleLoadError::UnsupportedField(field)),
},
)));
let payload = provider
.load_bound(DataRequest {
locale: &locale,
metadata: Default::default(),
locale,
key_attributes: &DataKeyAttributes::from_tinystr(key_attrs::symbol_attr_for(
match field_symbol {
fields::Month::Format => key_attrs::Context::Format,
fields::Month::StandAlone => key_attrs::Context::Standalone,
},
match field_length {
FieldLength::Abbreviated => key_attrs::Length::Abbr,
FieldLength::Narrow => key_attrs::Length::Narrow,
FieldLength::Wide => key_attrs::Length::Wide,
_ => return Err(SingleLoadError::UnsupportedField(field)),
},
)),
..Default::default()
})
.and_then(DataResponse::take_payload)
.map_err(SingleLoadError::Data)?;
Expand Down Expand Up @@ -1024,21 +1022,20 @@ impl<R: DateTimeNamesMarker> RawDateTimeNames<R> {
NamePresence::NotLoaded => (),
NamePresence::Mismatched => return Err(SingleLoadError::DuplicateField(field)),
};
let mut locale = locale.clone();
locale.set_aux(AuxiliaryKeys::from_subtag(aux::symbol_subtag_for(
aux::Context::Format,
match field_length {
FieldLength::Abbreviated => aux::Length::Abbr,
FieldLength::Narrow => aux::Length::Narrow,
FieldLength::Wide => aux::Length::Wide,
_ => return Err(SingleLoadError::UnsupportedField(field)),
},
)));
let payload = R::DayPeriodNames::load_from(
provider,
DataRequest {
locale: &locale,
metadata: Default::default(),
locale,
key_attributes: &DataKeyAttributes::from_tinystr(key_attrs::symbol_attr_for(
key_attrs::Context::Format,
match field_length {
FieldLength::Abbreviated => key_attrs::Length::Abbr,
FieldLength::Narrow => key_attrs::Length::Narrow,
FieldLength::Wide => key_attrs::Length::Wide,
_ => return Err(SingleLoadError::UnsupportedField(field)),
},
)),
..Default::default()
},
)
.ok_or(SingleLoadError::TypeTooNarrow(field))?
Expand Down Expand Up @@ -1076,25 +1073,26 @@ impl<R: DateTimeNamesMarker> RawDateTimeNames<R> {
NamePresence::NotLoaded => (),
NamePresence::Mismatched => return Err(SingleLoadError::DuplicateField(field)),
};
let mut locale = locale.clone();
locale.set_aux(AuxiliaryKeys::from_subtag(aux::symbol_subtag_for(
match field_symbol {
// UTS 35 says that "e" and "E" have the same non-numeric names
fields::Weekday::Format | fields::Weekday::Local => aux::Context::Format,
fields::Weekday::StandAlone => aux::Context::Standalone,
},
match field_length {
FieldLength::Abbreviated => aux::Length::Abbr,
FieldLength::Narrow => aux::Length::Narrow,
FieldLength::Wide => aux::Length::Wide,
FieldLength::Six => aux::Length::Short,
_ => return Err(SingleLoadError::UnsupportedField(field)),
},
)));
let payload = provider
.load_bound(DataRequest {
locale: &locale,
metadata: Default::default(),
locale,
key_attributes: &DataKeyAttributes::from_tinystr(key_attrs::symbol_attr_for(
match field_symbol {
// UTS 35 says that "e" and "E" have the same non-numeric names
fields::Weekday::Format | fields::Weekday::Local => {
key_attrs::Context::Format
}
fields::Weekday::StandAlone => key_attrs::Context::Standalone,
},
match field_length {
FieldLength::Abbreviated => key_attrs::Length::Abbr,
FieldLength::Narrow => key_attrs::Length::Narrow,
FieldLength::Wide => key_attrs::Length::Wide,
FieldLength::Six => key_attrs::Length::Short,
_ => return Err(SingleLoadError::UnsupportedField(field)),
},
)),
..Default::default()
})
.and_then(DataResponse::take_payload)
.map_err(SingleLoadError::Data)?;
Expand Down
6 changes: 3 additions & 3 deletions components/datetime/src/provider/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ where
Ok(data_provider
.load(DataRequest {
locale,
metadata: Default::default(),
..Default::default()
})?
.take_payload()?
.map_project(|data, _| pattern_for_time_length_inner(data, length, &preferences).into()))
Expand Down Expand Up @@ -230,7 +230,7 @@ where
.data_provider
.load(DataRequest {
locale: self.locale,
metadata: Default::default(),
..Default::default()
})
.and_then(DataResponse::take_payload)
.map_err(PatternForLengthError::Data)?;
Expand Down Expand Up @@ -367,7 +367,7 @@ where
self.data_provider
.load(DataRequest {
locale: &locale,
metadata: Default::default(),
..Default::default()
})
.and_then(DataResponse::take_payload)
}
Expand Down
Loading
Loading