From 7067c87bbc1f86bc0f22b7c1afa65539bf13a985 Mon Sep 17 00:00:00 2001 From: Robert Bastian <4706271+robertbastian@users.noreply.github.com> Date: Tue, 5 Nov 2024 17:53:04 +0100 Subject: [PATCH] Finalise datetime errors (#5771) Fixes #4336 --- components/calendar/src/japanese.rs | 5 - components/calendar/src/types.rs | 2 +- components/datetime/src/fieldset.rs | 8 +- components/datetime/src/format/datetime.rs | 156 ++++++------ components/datetime/src/format/mod.rs | 1 - components/datetime/src/format/neo.rs | 239 ++++++++---------- components/datetime/src/lib.rs | 2 +- components/datetime/src/neo.rs | 40 +-- components/datetime/src/time_zone.rs | 32 +-- ffi/capi/bindings/c/DateFormatter.h | 13 +- ffi/capi/bindings/c/DateTimeFormatError.d.h | 30 +++ ffi/capi/bindings/c/DateTimeFormatError.h | 23 ++ ffi/capi/bindings/c/DateTimeFormatter.h | 9 +- ffi/capi/bindings/c/Error.d.h | 44 ---- ffi/capi/bindings/c/GregorianDateFormatter.h | 4 +- .../bindings/c/GregorianDateTimeFormatter.h | 4 +- .../c/GregorianZonedDateTimeFormatter.h | 7 +- ffi/capi/bindings/c/LocaleCanonicalizer.h | 6 +- ffi/capi/bindings/c/LocaleExpander.h | 6 +- ffi/capi/bindings/c/PatternLoadError.d.h | 33 +++ .../c/{Error.h => PatternLoadError.h} | 8 +- ffi/capi/bindings/c/TimeFormatter.h | 4 +- ffi/capi/bindings/c/ZonedDateTimeFormatter.h | 9 +- .../bindings/cpp/icu4x/DateFormatter.d.hpp | 13 +- ffi/capi/bindings/cpp/icu4x/DateFormatter.hpp | 33 +-- .../cpp/icu4x/DateTimeFormatError.d.hpp | 60 +++++ .../cpp/icu4x/DateTimeFormatError.hpp | 44 ++++ .../cpp/icu4x/DateTimeFormatter.d.hpp | 9 +- .../bindings/cpp/icu4x/DateTimeFormatter.hpp | 21 +- ffi/capi/bindings/cpp/icu4x/Error.d.hpp | 88 ------- ffi/capi/bindings/cpp/icu4x/Error.hpp | 58 ----- .../cpp/icu4x/GregorianDateFormatter.d.hpp | 4 +- .../cpp/icu4x/GregorianDateFormatter.hpp | 8 +- .../icu4x/GregorianDateTimeFormatter.d.hpp | 4 +- .../cpp/icu4x/GregorianDateTimeFormatter.hpp | 8 +- .../GregorianZonedDateTimeFormatter.d.hpp | 7 +- .../icu4x/GregorianZonedDateTimeFormatter.hpp | 15 +- .../cpp/icu4x/LocaleCanonicalizer.d.hpp | 6 +- .../cpp/icu4x/LocaleCanonicalizer.hpp | 14 +- .../bindings/cpp/icu4x/LocaleExpander.d.hpp | 6 +- .../bindings/cpp/icu4x/LocaleExpander.hpp | 14 +- .../bindings/cpp/icu4x/PatternLoadError.d.hpp | 66 +++++ .../bindings/cpp/icu4x/PatternLoadError.hpp | 47 ++++ .../bindings/cpp/icu4x/TimeFormatter.d.hpp | 4 +- ffi/capi/bindings/cpp/icu4x/TimeFormatter.hpp | 8 +- .../cpp/icu4x/ZonedDateTimeFormatter.d.hpp | 9 +- .../cpp/icu4x/ZonedDateTimeFormatter.hpp | 21 +- ffi/capi/bindings/dart/DateFormatter.g.dart | 20 +- .../bindings/dart/DateTimeFormatError.g.dart | 47 ++++ .../bindings/dart/DateTimeFormatter.g.dart | 12 +- ffi/capi/bindings/dart/Error.g.dart | 107 -------- .../dart/GregorianDateFormatter.g.dart | 4 +- .../dart/GregorianDateTimeFormatter.g.dart | 4 +- .../GregorianZonedDateTimeFormatter.g.dart | 8 +- .../bindings/dart/LocaleCanonicalizer.g.dart | 8 +- ffi/capi/bindings/dart/LocaleExpander.g.dart | 8 +- .../bindings/dart/PatternLoadError.g.dart | 59 +++++ ffi/capi/bindings/dart/TimeFormatter.g.dart | 4 +- .../dart/ZonedDateTimeFormatter.g.dart | 12 +- ffi/capi/bindings/dart/lib.g.dart | 3 +- ffi/capi/bindings/js/DateFormatter.d.ts | 3 +- ffi/capi/bindings/js/DateFormatter.mjs | 23 +- ffi/capi/bindings/js/DateTimeFormatError.d.ts | 23 ++ ffi/capi/bindings/js/DateTimeFormatError.mjs | 84 ++++++ ffi/capi/bindings/js/DateTimeFormatter.d.ts | 3 +- ffi/capi/bindings/js/DateTimeFormatter.mjs | 15 +- ffi/capi/bindings/js/Error.d.ts | 39 --- ffi/capi/bindings/js/Error.mjs | 128 ---------- .../bindings/js/GregorianDateFormatter.d.ts | 2 +- .../bindings/js/GregorianDateFormatter.mjs | 6 +- .../js/GregorianDateTimeFormatter.d.ts | 2 +- .../js/GregorianDateTimeFormatter.mjs | 6 +- .../js/GregorianZonedDateTimeFormatter.d.ts | 3 +- .../js/GregorianZonedDateTimeFormatter.mjs | 11 +- ffi/capi/bindings/js/LocaleCanonicalizer.d.ts | 2 +- ffi/capi/bindings/js/LocaleCanonicalizer.mjs | 10 +- ffi/capi/bindings/js/LocaleExpander.d.ts | 2 +- ffi/capi/bindings/js/LocaleExpander.mjs | 10 +- ffi/capi/bindings/js/PatternLoadError.d.ts | 26 ++ ffi/capi/bindings/js/PatternLoadError.mjs | 93 +++++++ ffi/capi/bindings/js/TimeFormatter.d.ts | 2 +- ffi/capi/bindings/js/TimeFormatter.mjs | 6 +- .../bindings/js/ZonedDateTimeFormatter.d.ts | 3 +- .../bindings/js/ZonedDateTimeFormatter.mjs | 15 +- ffi/capi/bindings/js/index.d.ts | 4 +- ffi/capi/bindings/js/index.mjs | 4 +- ffi/capi/src/datetime_formatter.rs | 48 ++-- ffi/capi/src/errors.rs | 135 +++++----- ffi/capi/src/locale.rs | 12 +- ffi/capi/src/zoned_formatter.rs | 20 +- ffi/capi/tests/missing_apis.txt | 1 + tools/make/diplomat-coverage/src/allowlist.rs | 2 - 92 files changed, 1242 insertions(+), 1049 deletions(-) create mode 100644 ffi/capi/bindings/c/DateTimeFormatError.d.h create mode 100644 ffi/capi/bindings/c/DateTimeFormatError.h delete mode 100644 ffi/capi/bindings/c/Error.d.h create mode 100644 ffi/capi/bindings/c/PatternLoadError.d.h rename ffi/capi/bindings/c/{Error.h => PatternLoadError.h} (51%) create mode 100644 ffi/capi/bindings/cpp/icu4x/DateTimeFormatError.d.hpp create mode 100644 ffi/capi/bindings/cpp/icu4x/DateTimeFormatError.hpp delete mode 100644 ffi/capi/bindings/cpp/icu4x/Error.d.hpp delete mode 100644 ffi/capi/bindings/cpp/icu4x/Error.hpp create mode 100644 ffi/capi/bindings/cpp/icu4x/PatternLoadError.d.hpp create mode 100644 ffi/capi/bindings/cpp/icu4x/PatternLoadError.hpp create mode 100644 ffi/capi/bindings/dart/DateTimeFormatError.g.dart delete mode 100644 ffi/capi/bindings/dart/Error.g.dart create mode 100644 ffi/capi/bindings/dart/PatternLoadError.g.dart create mode 100644 ffi/capi/bindings/js/DateTimeFormatError.d.ts create mode 100644 ffi/capi/bindings/js/DateTimeFormatError.mjs delete mode 100644 ffi/capi/bindings/js/Error.d.ts delete mode 100644 ffi/capi/bindings/js/Error.mjs create mode 100644 ffi/capi/bindings/js/PatternLoadError.d.ts create mode 100644 ffi/capi/bindings/js/PatternLoadError.mjs diff --git a/components/calendar/src/japanese.rs b/components/calendar/src/japanese.rs index 2f90facd5a9..1afc091a41d 100644 --- a/components/calendar/src/japanese.rs +++ b/components/calendar/src/japanese.rs @@ -505,11 +505,6 @@ impl Date { .new_japanese_date_inner(era, year, month, day)?; Ok(Date::from_raw(inner, japanext_calendar)) } - - #[doc(hidden)] // for testing - pub fn into_japanese_date(self) -> Date { - Date::from_raw(self.inner, self.calendar.0) - } } impl DateTime { diff --git a/components/calendar/src/types.rs b/components/calendar/src/types.rs index 50555900346..d152f6e0436 100644 --- a/components/calendar/src/types.rs +++ b/components/calendar/src/types.rs @@ -146,7 +146,7 @@ pub enum FormattingEra { impl FormattingEra { /// Get a fallback era name suitable for display to the user when the real era name is not availabe - pub fn fallback_era(self) -> TinyStr16 { + pub fn fallback_name(self) -> TinyStr16 { match self { Self::Index(_idx, fallback) => fallback, Self::Code(era) => era.0, diff --git a/components/datetime/src/fieldset.rs b/components/datetime/src/fieldset.rs index a616b92f813..8bc0df1243d 100644 --- a/components/datetime/src/fieldset.rs +++ b/components/datetime/src/fieldset.rs @@ -1085,7 +1085,7 @@ impl_zone_marker!( /// use icu::calendar::Gregorian; /// use icu::datetime::FixedCalendarDateTimeFormatter; /// use icu::datetime::fieldset::Zs; - /// use icu::datetime::LoadError; + /// use icu::datetime::PatternLoadError; /// use icu::locale::locale; /// /// let result = FixedCalendarDateTimeFormatter::::try_new( @@ -1093,7 +1093,7 @@ impl_zone_marker!( /// Zs::long(), /// ); /// - /// assert!(matches!(result, Err(LoadError::TypeTooNarrow(_)))); + /// assert!(matches!(result, Err(PatternLoadError::TypeTooSpecific(_)))); /// ``` /// /// This style requires a [`ZoneVariant`], so @@ -1302,7 +1302,7 @@ impl_zone_marker!( /// use icu::calendar::Gregorian; /// use icu::datetime::FixedCalendarDateTimeFormatter; /// use icu::datetime::fieldset::Vs; - /// use icu::datetime::LoadError; + /// use icu::datetime::PatternLoadError; /// use icu::locale::locale; /// /// let result = FixedCalendarDateTimeFormatter::::try_new( @@ -1310,7 +1310,7 @@ impl_zone_marker!( /// Vs::long(), /// ); /// - /// assert!(matches!(result, Err(LoadError::TypeTooNarrow(_)))); + /// assert!(matches!(result, Err(PatternLoadError::TypeTooSpecific(_)))); /// ``` /// /// Since non-location names might change over time, diff --git a/components/datetime/src/format/datetime.rs b/components/datetime/src/format/datetime.rs index 8f5ad9ff02d..2ac36117cbd 100644 --- a/components/datetime/src/format/datetime.rs +++ b/components/datetime/src/format/datetime.rs @@ -15,6 +15,10 @@ use crate::time_zone::{ FormatTimeZone, FormatTimeZoneError, Iso8601Format, IsoFormat, IsoMinutes, IsoSeconds, ResolvedNeoTimeZoneSkeleton, }; +#[cfg(doc)] +use crate::TypedDateTimeNames; +#[cfg(doc)] +use icu_calendar::types::YearInfo; use core::fmt::{self, Write}; use fixed_decimal::FixedDecimal; @@ -60,7 +64,7 @@ where Ok(Ok(())) } else { result.with_part(writeable::Part::ERROR, |r| num.write_to(r))?; - Ok(Err(DateTimeWriteError::MissingFixedDecimalFormatter)) + Ok(Err(DateTimeWriteError::FixedDecimalFormatterNotLoaded)) } } @@ -99,45 +103,67 @@ where #[derive(Debug, PartialEq, Copy, Clone, displaydoc::Display)] /// Error for `TryWriteable` implementations pub enum DateTimeWriteError { - // Data not loaded - /// Missing FixedDecimalFormatter - #[displaydoc("FixedDecimalFormatter not loaded")] - MissingFixedDecimalFormatter, - /// Missing OrdinalRules - #[displaydoc("OrdinalRules not loaded")] - MissingOrdinalRules, - /// Missing WeekCalculator - #[displaydoc("WeekCalculator not loaded")] - MissingWeekCalculator, - /// TODO - #[displaydoc("Names for {0:?} not loaded")] - MissingNames(Field), - - // Something not found in data - // TODO: Are these actionable? Can clients even invent their own months and days? - /// Missing month symbol - #[displaydoc("Cannot find symbol for month {0:?}")] - MissingMonthSymbol(MonthCode), - /// Missing era symbol - #[displaydoc("Cannot find symbol for era {0:?}")] - MissingEraSymbol(FormattingEra), - /// Missing weekday symbol - #[displaydoc("Cannot find symbol for weekday {0:?}")] - MissingWeekdaySymbol(IsoWeekday), - - // Invalid input - /// Incomplete input - #[displaydoc("Incomplete input, missing value for {0:?}")] - MissingInputField(&'static str), - /// Cyclic year overflow - #[displaydoc("Cyclic year overflow, found {value}, maximum {max}")] - CyclicYearOverflow { + /// The [`MonthCode`] of the input is not valid for this calendar. + /// + /// This is guaranteed not to happen for `icu::calendar` inputs, but may happen for custom inputs. + /// + /// The output will contain the raw [`MonthCode`] as a fallback value. + #[displaydoc("Invalid month {0:?}")] + InvalidMonthCode(MonthCode), + /// The [`FormattingEra`] of the input is not valid for this calendar. + /// + /// This is guaranteed not to happen for `icu::calendar` inputs, but may happen for custom inputs. + /// + /// The output will contain [`FormattingEra::fallback_name`] as the fallback. + #[displaydoc("Invalid era {0:?}")] + InvalidEra(FormattingEra), + /// The [`YearInfo::cyclic`] of the input is not valid for this calendar. + /// + /// This is guaranteed not to happen for `icu::calendar` inputs, but may happen for custom inputs. + /// + /// The output will contain [`YearInfo::extended_year`] as a fallback value. + #[displaydoc("Invalid cyclic year {value} (maximum {max})")] + InvalidCyclicYear { /// Value value: usize, /// Max max: usize, }, + + /// The [`FixedDecimalFormatter`] has not been loaded. + /// + /// This *only* happens if the formatter has been created using + /// [`TypedDateTimeNames::with_pattern`], the pattern requires decimal + /// formatting, and the decimal formatter was not loaded. + /// + /// The output will contain fallback values using Latin numerals. + #[displaydoc("FixedDecimalFormatter not loaded")] + FixedDecimalFormatterNotLoaded, + /// The localized names for a field have not been loaded. + /// + /// This *only* happens if the formatter has been created using + /// [`TypedDateTimeNames::with_pattern`], and the pattern requires names + /// that were not loaded. + /// + /// The output will contain fallback values using field identifiers (such as `tue` for `IsoWeekday::Tuesday`, + /// `M02` for month 2, etc.). + #[displaydoc("Names for {0:?} not loaded")] + NamesNotLoaded(Field), + /// An input field (such as "hour" or "month") is missing. + /// + /// This *only* happens if the formatter has been created using + /// [`TypedDateTimeNames::with_pattern`], and the pattern requires fields + /// that are not returned by the input type. + /// + /// The output will contain the string `{X}` instead, where `X` is the symbol for which the input is missing. + #[displaydoc("Incomplete input, missing value for {0:?}")] + MissingInputField(&'static str), /// Unsupported field + /// + /// This *only* happens if the formatter has been created using + /// [`TypedDateTimeNames::with_pattern`], and the pattern contains unsupported fields. + /// + /// The output will contain the string `{unsupported:X}`, where `X` is the symbol of the unsupported field. #[displaydoc("Unsupported field {0:?}")] UnsupportedField(Field), } @@ -185,16 +211,14 @@ where let era_symbol = datetime_names .get_name_for_era(l, era) .map_err(|e| match e { - GetSymbolForEraError::Missing => { - DateTimeWriteError::MissingEraSymbol(era) - } + GetSymbolForEraError::Missing => DateTimeWriteError::InvalidEra(era), GetSymbolForEraError::MissingNames(f) => { - DateTimeWriteError::MissingNames(f) + DateTimeWriteError::NamesNotLoaded(f) } }); match era_symbol { Err(e) => { - w.with_part(Part::ERROR, |w| w.write_str(&era.fallback_era()))?; + w.with_part(Part::ERROR, |w| w.write_str(&era.fallback_name()))?; Err(e) } Ok(era) => Ok(w.write_str(era)?), @@ -246,7 +270,7 @@ where let value: usize = cyclic.get() as usize; cyclics .get(value - 1) - .ok_or(DateTimeWriteError::CyclicYearOverflow { + .ok_or(DateTimeWriteError::InvalidCyclicYear { value, max: cyclics.len() + 1, }) @@ -296,9 +320,9 @@ where .get_name_for_month(month, l, month_info.formatting_code) .map_err(|e| match e { GetNameForMonthError::Missing => { - DateTimeWriteError::MissingMonthSymbol(month_info.formatting_code) + DateTimeWriteError::InvalidMonthCode(month_info.formatting_code) } - GetNameForMonthError::MissingNames(f) => DateTimeWriteError::MissingNames(f), + GetNameForMonthError::MissingNames(f) => DateTimeWriteError::NamesNotLoaded(f), }) { Err(e) => { w.with_part(Part::ERROR, |w| w.write_str(&month_info.formatting_code.0))?; @@ -327,8 +351,9 @@ where Some(wd) => match datetime_names .get_name_for_weekday(weekday, l, wd) .map_err(|e| match e { - GetNameForWeekdayError::Missing => DateTimeWriteError::MissingWeekdaySymbol(wd), - GetNameForWeekdayError::MissingNames(f) => DateTimeWriteError::MissingNames(f), + GetNameForWeekdayError::MissingNames(f) => { + DateTimeWriteError::NamesNotLoaded(f) + } }) { Err(e) => { w.with_part(Part::ERROR, |w| { @@ -447,7 +472,7 @@ where ) .map_err(|e| match e { GetNameForDayPeriodError::MissingNames(f) => { - DateTimeWriteError::MissingNames(f) + DateTimeWriteError::NamesNotLoaded(f) } }) { Err(e) => { @@ -494,8 +519,8 @@ where Err(DateTimeWriteError::MissingInputField(f)) } Err( - e @ (FormatTimeZoneError::MissingFixedDecimalFormatter - | FormatTimeZoneError::MissingZoneSymbols), + e @ (FormatTimeZoneError::FixedDecimalFormatterNotLoaded + | FormatTimeZoneError::NamesNotLoaded), ) => { if let Some(offset) = input.offset { w.with_part(Part::ERROR, |w| { @@ -510,11 +535,11 @@ where write_value_missing(w, field)?; } Err(match e { - FormatTimeZoneError::MissingFixedDecimalFormatter => { - DateTimeWriteError::MissingFixedDecimalFormatter + FormatTimeZoneError::FixedDecimalFormatterNotLoaded => { + DateTimeWriteError::FixedDecimalFormatterNotLoaded } - FormatTimeZoneError::MissingZoneSymbols => { - DateTimeWriteError::MissingNames(field) + FormatTimeZoneError::NamesNotLoaded => { + DateTimeWriteError::NamesNotLoaded(field) } _ => unreachable!(), }) @@ -556,36 +581,7 @@ where #[cfg(feature = "compiled_data")] mod tests { use super::*; - use crate::{fieldset::YMD, neo_skeleton::NeoSkeletonLength, provider::pattern::runtime}; - use icu_calendar::types::FormattingEra; use icu_decimal::options::{FixedDecimalFormatterOptions, GroupingStrategy}; - use tinystr::tinystr; - - #[test] - fn test_mixed_calendar_eras() { - use crate::neo::DateTimeFormatter; - use crate::options::length; - use icu_calendar::cal::JapaneseExtended; - use icu_calendar::Date; - - let locale = icu::locale::locale!("en-u-ca-japanese"); - let dtf = DateTimeFormatter::try_new(&locale.into(), YMD::medium()) - .expect("DateTimeFormat construction succeeds"); - - let date = Date::try_new_gregorian(1800, 9, 1).expect("Failed to construct Date."); - let date = date - .to_calendar(JapaneseExtended::new()) - .into_japanese_date() - .to_any(); - - writeable::assert_try_writeable_eq!( - dtf.strict_format(&date).unwrap(), - "Sep 1, 12 kansei-1789", - Err(DateTimeWriteError::MissingEraSymbol(FormattingEra::Code( - tinystr!(16, "kansei-1789").into() - ))) - ); - } #[test] fn test_format_number() { diff --git a/components/datetime/src/format/mod.rs b/components/datetime/src/format/mod.rs index dc0d212b06b..7ffab0d584b 100644 --- a/components/datetime/src/format/mod.rs +++ b/components/datetime/src/format/mod.rs @@ -13,7 +13,6 @@ pub(crate) enum GetNameForMonthError { MissingNames(Field), } pub(crate) enum GetNameForWeekdayError { - Missing, MissingNames(Field), } diff --git a/components/datetime/src/format/neo.rs b/components/datetime/src/format/neo.rs index 01c34999070..e30fd0a8819 100644 --- a/components/datetime/src/format/neo.rs +++ b/components/datetime/src/format/neo.rs @@ -69,15 +69,15 @@ impl_holder_trait!(tz::MzPeriodV1Marker); #[non_exhaustive] pub enum MaybePayloadError2 { - TypeTooNarrow, - InsufficientStorage, + TypeTooSpecific, + ConflictingField, } impl MaybePayloadError2 { - fn into_single_load_error(self, field: Field) -> SingleLoadError { + fn into_load_error(self, field: Field) -> PatternLoadError { match self { - Self::TypeTooNarrow => SingleLoadError::TypeTooNarrow(field), - Self::InsufficientStorage => SingleLoadError::DuplicateField(field), + Self::TypeTooSpecific => PatternLoadError::TypeTooSpecific(field), + Self::ConflictingField => PatternLoadError::ConflictingField(field), } } } @@ -150,7 +150,7 @@ where return Ok(Ok(())); } OptionalNames::SingleLength { .. } => { - return Err(MaybePayloadError2::InsufficientStorage); + return Err(MaybePayloadError2::ConflictingField); } OptionalNames::None => (), }; @@ -187,7 +187,7 @@ impl MaybePayload2 for () { P: BoundDataProvider + ?Sized, Self: Sized, { - Err(MaybePayloadError2::TypeTooNarrow) + Err(MaybePayloadError2::TypeTooSpecific) } #[allow(clippy::needless_lifetimes)] // Yokeable is involved #[inline] @@ -346,7 +346,7 @@ size_test!( /// assert_try_writeable_parts_eq!( /// names.with_pattern(&pattern).format(&dtz), /// "It is: mon M11 20 2023 CE at 11:35:03.000 AM +0000", -/// Err(DateTimeWriteError::MissingNames(Field { symbol: FieldSymbol::Weekday(Weekday::Format), length: FieldLength::One })), +/// Err(DateTimeWriteError::NamesNotLoaded(Field { symbol: FieldSymbol::Weekday(Weekday::Format), length: FieldLength::One })), /// [ /// (7, 10, Part::ERROR), // mon /// (11, 14, Part::ERROR), // M11 @@ -670,7 +670,7 @@ impl TypedDateTimeNames { /// assert_try_writeable_parts_eq!( /// names.with_pattern(&pattern).format(&date), /// "It is: 2024-7-1", - /// Err(DateTimeWriteError::MissingFixedDecimalFormatter), + /// Err(DateTimeWriteError::FixedDecimalFormatterNotLoaded), /// [ /// (7, 11, Part::ERROR), // 2024 /// (12, 13, Part::ERROR), // 7 @@ -693,7 +693,7 @@ impl TypedDateTimeNames { &mut self, provider: &P, field_length: FieldLength, - ) -> Result<&mut Self, SingleLoadError> + ) -> Result<&mut Self, PatternLoadError> where P: DataProvider + ?Sized, { @@ -714,7 +714,7 @@ impl TypedDateTimeNames { /// ``` /// use icu::calendar::Gregorian; /// use icu::datetime::fields::FieldLength; - /// use icu::datetime::SingleLoadError; + /// use icu::datetime::PatternLoadError; /// use icu::datetime::TypedDateTimeNames; /// use icu::locale::locale; /// @@ -731,14 +731,14 @@ impl TypedDateTimeNames { /// // But loading a new length fails: /// assert!(matches!( /// names.include_year_names(FieldLength::Abbreviated), - /// Err(SingleLoadError::DuplicateField(_)) + /// Err(PatternLoadError::ConflictingField(_)) /// )); /// ``` #[cfg(feature = "compiled_data")] pub fn include_year_names( &mut self, field_length: FieldLength, - ) -> Result<&mut Self, SingleLoadError> + ) -> Result<&mut Self, PatternLoadError> where crate::provider::Baked: icu_provider::DataProvider<::YearNamesV1Marker>, { @@ -753,7 +753,7 @@ impl TypedDateTimeNames { provider: &P, field_symbol: fields::Month, field_length: FieldLength, - ) -> Result<&mut Self, SingleLoadError> + ) -> Result<&mut Self, PatternLoadError> where P: DataProvider + ?Sized, { @@ -775,7 +775,7 @@ impl TypedDateTimeNames { /// ``` /// use icu::calendar::Gregorian; /// use icu::datetime::fields::FieldLength; - /// use icu::datetime::SingleLoadError; + /// use icu::datetime::PatternLoadError; /// use icu::datetime::TypedDateTimeNames; /// use icu::locale::locale; /// @@ -798,11 +798,11 @@ impl TypedDateTimeNames { /// // But loading a new symbol or length fails: /// assert!(matches!( /// names.include_month_names(alt_field_symbol, FieldLength::Wide), - /// Err(SingleLoadError::DuplicateField(_)) + /// Err(PatternLoadError::ConflictingField(_)) /// )); /// assert!(matches!( /// names.include_month_names(field_symbol, FieldLength::Abbreviated), - /// Err(SingleLoadError::DuplicateField(_)) + /// Err(PatternLoadError::ConflictingField(_)) /// )); /// ``` #[cfg(feature = "compiled_data")] @@ -810,7 +810,7 @@ impl TypedDateTimeNames { &mut self, field_symbol: fields::Month, field_length: FieldLength, - ) -> Result<&mut Self, SingleLoadError> + ) -> Result<&mut Self, PatternLoadError> where crate::provider::Baked: icu_provider::DataProvider<::MonthNamesV1Marker>, { @@ -824,7 +824,7 @@ impl TypedDateTimeNames { &mut self, provider: &P, field_length: FieldLength, - ) -> Result<&mut Self, SingleLoadError> + ) -> Result<&mut Self, PatternLoadError> where P: DataProvider + ?Sized, { @@ -843,7 +843,7 @@ impl TypedDateTimeNames { /// ``` /// use icu::calendar::Gregorian; /// use icu::datetime::fields::FieldLength; - /// use icu::datetime::SingleLoadError; + /// use icu::datetime::PatternLoadError; /// use icu::datetime::TypedDateTimeNames; /// use icu::locale::locale; /// @@ -860,14 +860,14 @@ impl TypedDateTimeNames { /// // But loading a new length fails: /// assert!(matches!( /// names.include_day_period_names(FieldLength::Abbreviated), - /// Err(SingleLoadError::DuplicateField(_)) + /// Err(PatternLoadError::ConflictingField(_)) /// )); /// ``` #[cfg(feature = "compiled_data")] pub fn include_day_period_names( &mut self, field_length: FieldLength, - ) -> Result<&mut Self, SingleLoadError> + ) -> Result<&mut Self, PatternLoadError> where crate::provider::Baked: icu_provider::DataProvider, { @@ -882,7 +882,7 @@ impl TypedDateTimeNames { provider: &P, field_symbol: fields::Weekday, field_length: FieldLength, - ) -> Result<&mut Self, SingleLoadError> + ) -> Result<&mut Self, PatternLoadError> where P: DataProvider + ?Sized, { @@ -904,7 +904,7 @@ impl TypedDateTimeNames { /// ``` /// use icu::calendar::Gregorian; /// use icu::datetime::fields::FieldLength; - /// use icu::datetime::SingleLoadError; + /// use icu::datetime::PatternLoadError; /// use icu::datetime::TypedDateTimeNames; /// use icu::locale::locale; /// @@ -927,11 +927,11 @@ impl TypedDateTimeNames { /// // But loading a new symbol or length fails: /// assert!(matches!( /// names.include_weekday_names(alt_field_symbol, FieldLength::Wide), - /// Err(SingleLoadError::DuplicateField(_)) + /// Err(PatternLoadError::ConflictingField(_)) /// )); /// assert!(matches!( /// names.include_weekday_names(field_symbol, FieldLength::Abbreviated), - /// Err(SingleLoadError::DuplicateField(_)) + /// Err(PatternLoadError::ConflictingField(_)) /// )); /// ``` #[cfg(feature = "compiled_data")] @@ -939,7 +939,7 @@ impl TypedDateTimeNames { &mut self, field_symbol: fields::Weekday, field_length: FieldLength, - ) -> Result<&mut Self, SingleLoadError> + ) -> Result<&mut Self, PatternLoadError> where crate::provider::Baked: icu_provider::DataProvider, { @@ -950,7 +950,7 @@ impl TypedDateTimeNames { pub fn load_time_zone_essentials

( &mut self, provider: &P, - ) -> Result<&mut Self, SingleLoadError> + ) -> Result<&mut Self, PatternLoadError> where P: DataProvider + ?Sized, { @@ -1039,7 +1039,7 @@ impl TypedDateTimeNames { /// ); /// ``` #[cfg(feature = "compiled_data")] - pub fn include_time_zone_essentials(&mut self) -> Result<&mut Self, SingleLoadError> + pub fn include_time_zone_essentials(&mut self) -> Result<&mut Self, PatternLoadError> where crate::provider::Baked: icu_provider::DataProvider, { @@ -1050,7 +1050,7 @@ impl TypedDateTimeNames { pub fn load_time_zone_location_names

( &mut self, provider: &P, - ) -> Result<&mut Self, SingleLoadError> + ) -> Result<&mut Self, PatternLoadError> where P: DataProvider + ?Sized, { @@ -1103,7 +1103,7 @@ impl TypedDateTimeNames { /// ); /// ``` #[cfg(feature = "compiled_data")] - pub fn include_time_zone_location_names(&mut self) -> Result<&mut Self, SingleLoadError> + pub fn include_time_zone_location_names(&mut self) -> Result<&mut Self, PatternLoadError> where crate::provider::Baked: icu_provider::DataProvider, { @@ -1114,7 +1114,7 @@ impl TypedDateTimeNames { pub fn load_time_zone_generic_long_names

( &mut self, provider: &P, - ) -> Result<&mut Self, SingleLoadError> + ) -> Result<&mut Self, PatternLoadError> where P: DataProvider + DataProvider + ?Sized, { @@ -1179,7 +1179,7 @@ impl TypedDateTimeNames { /// ); /// ``` #[cfg(feature = "compiled_data")] - pub fn include_time_zone_generic_long_names(&mut self) -> Result<&mut Self, SingleLoadError> + pub fn include_time_zone_generic_long_names(&mut self) -> Result<&mut Self, PatternLoadError> where crate::provider::Baked: icu_provider::DataProvider, { @@ -1190,7 +1190,7 @@ impl TypedDateTimeNames { pub fn load_time_zone_generic_short_names

( &mut self, provider: &P, - ) -> Result<&mut Self, SingleLoadError> + ) -> Result<&mut Self, PatternLoadError> where P: DataProvider + DataProvider + ?Sized, { @@ -1255,7 +1255,7 @@ impl TypedDateTimeNames { /// ); /// ``` #[cfg(feature = "compiled_data")] - pub fn include_time_zone_generic_short_names(&mut self) -> Result<&mut Self, SingleLoadError> + pub fn include_time_zone_generic_short_names(&mut self) -> Result<&mut Self, PatternLoadError> where crate::provider::Baked: icu_provider::DataProvider, { @@ -1266,7 +1266,7 @@ impl TypedDateTimeNames { pub fn load_time_zone_specific_long_names

( &mut self, provider: &P, - ) -> Result<&mut Self, SingleLoadError> + ) -> Result<&mut Self, PatternLoadError> where P: DataProvider + DataProvider + ?Sized, { @@ -1331,7 +1331,7 @@ impl TypedDateTimeNames { /// ); /// ``` #[cfg(feature = "compiled_data")] - pub fn include_time_zone_specific_long_names(&mut self) -> Result<&mut Self, SingleLoadError> + pub fn include_time_zone_specific_long_names(&mut self) -> Result<&mut Self, PatternLoadError> where crate::provider::Baked: icu_provider::DataProvider, { @@ -1342,7 +1342,7 @@ impl TypedDateTimeNames { pub fn load_time_zone_specific_short_names

( &mut self, provider: &P, - ) -> Result<&mut Self, SingleLoadError> + ) -> Result<&mut Self, PatternLoadError> where P: DataProvider + DataProvider + ?Sized, { @@ -1407,7 +1407,7 @@ impl TypedDateTimeNames { /// ); /// ``` #[cfg(feature = "compiled_data")] - pub fn include_time_zone_specific_short_names(&mut self) -> Result<&mut Self, SingleLoadError> + pub fn include_time_zone_specific_short_names(&mut self) -> Result<&mut Self, PatternLoadError> where crate::provider::Baked: icu_provider::DataProvider, { @@ -1484,7 +1484,7 @@ impl TypedDateTimeNames { &'l mut self, provider: &P, pattern: &'l DateTimePattern, - ) -> Result, LoadError> + ) -> Result, PatternLoadError> where P: DataProvider + DataProvider @@ -1565,7 +1565,7 @@ impl TypedDateTimeNames { pub fn include_for_pattern<'l>( &'l mut self, pattern: &'l DateTimePattern, - ) -> Result, LoadError> + ) -> Result, PatternLoadError> where crate::provider::Baked: DataProvider + DataProvider @@ -1601,45 +1601,27 @@ impl TypedDateTimeNames { } } -#[derive(Debug, Clone, Copy, PartialEq, displaydoc::Display)] -#[non_exhaustive] -/// Error returned from [`TypedDateTimeNames`]'s load methods. -pub enum SingleLoadError { - /// Duplicate field in pattern - DuplicateField(Field), - /// ICU4X does not support this field - UnsupportedField(Field), - /// The specific type does not support this field - TypeTooNarrow(Field), - /// An error arising from the [`DataProvider`] - Data(DataError), -} - #[derive(Debug, Clone, Copy, PartialEq, displaydoc::Display)] /// Error returned from [`TypedDateTimeNames`]'s pattern load methods. #[non_exhaustive] -pub enum LoadError { - /// DuplicateField - DuplicateField(Field), - /// ICU4X does not support this field +pub enum PatternLoadError { + /// A field conflicts with a previous field. + /// + /// Fields conflict if they require the same type of data, for example the + /// `EEE` and `EEEE` fields (short vs long weekday) conflict, or the `M` + /// and `L` (format vs standalone month) conflict. + #[displaydoc("A field conflicts with a previous field.")] + ConflictingField(Field), + /// The field is not currently supported. UnsupportedField(Field), - /// The specific type does not support this field - TypeTooNarrow(Field), - /// An error arising from the [`DataProvider`] + /// The specific type does not support this field. + /// + /// This happens for example when trying to load a month field + /// on a [`TypedDateTimeNames`]. + #[displaydoc("The specific type does not support this field.")] + TypeTooSpecific(Field), + /// An error arising from the [`DataProvider`]. Data(DataError), - /// MissingNames - MissingNames(Field), -} - -impl From for LoadError { - fn from(value: SingleLoadError) -> Self { - match value { - SingleLoadError::Data(e) => LoadError::Data(e), - SingleLoadError::UnsupportedField(f) => LoadError::UnsupportedField(f), - SingleLoadError::TypeTooNarrow(f) => LoadError::TypeTooNarrow(f), - SingleLoadError::DuplicateField(f) => LoadError::DuplicateField(f), - } - } } pub(crate) enum FieldForDataLoading { @@ -1699,7 +1681,7 @@ impl RawDateTimeNames { provider: &P, locale: &DataLocale, field_length: FieldLength, - ) -> Result<(), SingleLoadError> + ) -> Result<(), PatternLoadError> where P: BoundDataProvider + ?Sized, { @@ -1718,7 +1700,7 @@ impl RawDateTimeNames { FieldLength::Abbreviated => marker_attrs::Length::Abbr, FieldLength::Narrow => marker_attrs::Length::Narrow, FieldLength::Wide => marker_attrs::Length::Wide, - _ => return Err(SingleLoadError::UnsupportedField(field)), + _ => return Err(PatternLoadError::UnsupportedField(field)), }, ), locale, @@ -1727,8 +1709,8 @@ impl RawDateTimeNames { }; self.year_names .load_put(provider, req, variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; Ok(()) } @@ -1738,7 +1720,7 @@ impl RawDateTimeNames { locale: &DataLocale, field_symbol: fields::Month, field_length: FieldLength, - ) -> Result<(), SingleLoadError> + ) -> Result<(), PatternLoadError> where P: BoundDataProvider + ?Sized, { @@ -1758,7 +1740,7 @@ impl RawDateTimeNames { FieldLength::Abbreviated => marker_attrs::Length::Abbr, FieldLength::Narrow => marker_attrs::Length::Narrow, FieldLength::Wide => marker_attrs::Length::Wide, - _ => return Err(SingleLoadError::UnsupportedField(field)), + _ => return Err(PatternLoadError::UnsupportedField(field)), }, ), locale, @@ -1767,8 +1749,8 @@ impl RawDateTimeNames { }; self.month_names .load_put(provider, req, variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; Ok(()) } @@ -1777,7 +1759,7 @@ impl RawDateTimeNames { provider: &P, locale: &DataLocale, field_length: FieldLength, - ) -> Result<(), SingleLoadError> + ) -> Result<(), PatternLoadError> where P: BoundDataProvider + ?Sized, { @@ -1797,7 +1779,7 @@ impl RawDateTimeNames { FieldLength::Abbreviated => marker_attrs::Length::Abbr, FieldLength::Narrow => marker_attrs::Length::Narrow, FieldLength::Wide => marker_attrs::Length::Wide, - _ => return Err(SingleLoadError::UnsupportedField(field)), + _ => return Err(PatternLoadError::UnsupportedField(field)), }, ), locale, @@ -1806,8 +1788,8 @@ impl RawDateTimeNames { }; self.dayperiod_names .load_put(provider, req, variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; Ok(()) } @@ -1817,7 +1799,7 @@ impl RawDateTimeNames { locale: &DataLocale, field_symbol: fields::Weekday, field_length: FieldLength, - ) -> Result<(), SingleLoadError> + ) -> Result<(), PatternLoadError> where P: BoundDataProvider + ?Sized, { @@ -1848,7 +1830,7 @@ impl RawDateTimeNames { FieldLength::Narrow => marker_attrs::Length::Narrow, FieldLength::Wide => marker_attrs::Length::Wide, FieldLength::Six => marker_attrs::Length::Short, - _ => return Err(SingleLoadError::UnsupportedField(field)), + _ => return Err(PatternLoadError::UnsupportedField(field)), }, ), locale, @@ -1857,8 +1839,8 @@ impl RawDateTimeNames { }; self.weekday_names .load_put(provider, req, variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; Ok(()) } @@ -1866,7 +1848,7 @@ impl RawDateTimeNames { &mut self, provider: &P, locale: &DataLocale, - ) -> Result<(), SingleLoadError> + ) -> Result<(), PatternLoadError> where P: BoundDataProvider + ?Sized, { @@ -1881,8 +1863,8 @@ impl RawDateTimeNames { }; self.zone_essentials .load_put(provider, req, variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; Ok(()) } @@ -1890,7 +1872,7 @@ impl RawDateTimeNames { &mut self, provider: &P, locale: &DataLocale, - ) -> Result<(), SingleLoadError> + ) -> Result<(), PatternLoadError> where P: BoundDataProvider + ?Sized, { @@ -1905,12 +1887,12 @@ impl RawDateTimeNames { }; self.locations_root .load_put(provider, Default::default(), variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; self.locations .load_put(provider, req, variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; Ok(()) } @@ -1919,7 +1901,7 @@ impl RawDateTimeNames { mz_generic_long_provider: &(impl BoundDataProvider + ?Sized), mz_period_provider: &(impl BoundDataProvider + ?Sized), locale: &DataLocale, - ) -> Result<(), SingleLoadError> { + ) -> Result<(), PatternLoadError> { let field = fields::Field { symbol: FieldSymbol::TimeZone(fields::TimeZone::LowerV), length: FieldLength::Wide, @@ -1931,12 +1913,12 @@ impl RawDateTimeNames { }; self.mz_generic_long .load_put(mz_generic_long_provider, req, variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; self.mz_periods .load_put(mz_period_provider, Default::default(), variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; Ok(()) } @@ -1945,7 +1927,7 @@ impl RawDateTimeNames { mz_generic_short_provider: &(impl BoundDataProvider + ?Sized), mz_period_provider: &(impl BoundDataProvider + ?Sized), locale: &DataLocale, - ) -> Result<(), SingleLoadError> { + ) -> Result<(), PatternLoadError> { let field = fields::Field { symbol: FieldSymbol::TimeZone(fields::TimeZone::LowerV), length: FieldLength::One, @@ -1957,12 +1939,12 @@ impl RawDateTimeNames { }; self.mz_generic_short .load_put(mz_generic_short_provider, req, variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; self.mz_periods .load_put(mz_period_provider, Default::default(), variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; Ok(()) } @@ -1971,7 +1953,7 @@ impl RawDateTimeNames { mz_specific_long_provider: &(impl BoundDataProvider + ?Sized), mz_period_provider: &(impl BoundDataProvider + ?Sized), locale: &DataLocale, - ) -> Result<(), SingleLoadError> { + ) -> Result<(), PatternLoadError> { let field = fields::Field { symbol: FieldSymbol::TimeZone(fields::TimeZone::LowerZ), length: FieldLength::Wide, @@ -1983,12 +1965,12 @@ impl RawDateTimeNames { }; self.mz_specific_long .load_put(mz_specific_long_provider, req, variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; self.mz_periods .load_put(mz_period_provider, Default::default(), variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; Ok(()) } @@ -1997,7 +1979,7 @@ impl RawDateTimeNames { mz_specific_short_provider: &(impl BoundDataProvider + ?Sized), mz_period_provider: &(impl BoundDataProvider + ?Sized), locale: &DataLocale, - ) -> Result<(), SingleLoadError> { + ) -> Result<(), PatternLoadError> { let field = fields::Field { symbol: FieldSymbol::TimeZone(fields::TimeZone::LowerZ), length: FieldLength::One, @@ -2009,12 +1991,12 @@ impl RawDateTimeNames { }; self.mz_specific_short .load_put(mz_specific_short_provider, req, variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; self.mz_periods .load_put(mz_period_provider, Default::default(), variables) - .map_err(|e| MaybePayloadError2::into_single_load_error(e, field))? - .map_err(SingleLoadError::Data)?; + .map_err(|e| MaybePayloadError2::into_load_error(e, field))? + .map_err(PatternLoadError::Data)?; Ok(()) } @@ -2067,7 +2049,7 @@ impl RawDateTimeNames { fixed_decimal_formatter_loader: &impl FixedDecimalFormatterLoader, locale: &DataLocale, pattern_items: impl Iterator, - ) -> Result<(), LoadError> { + ) -> Result<(), PatternLoadError> { let mut numeric_field = None; for item in pattern_items { let item = match item { @@ -2096,7 +2078,7 @@ impl RawDateTimeNames { fixed_decimal_formatter_loader, locale, ) - .map_err(LoadError::Data)?; + .map_err(PatternLoadError::Data)?; self.load_time_zone_specific_short_names( mz_specific_short_provider, mz_period_provider, @@ -2110,7 +2092,7 @@ impl RawDateTimeNames { fixed_decimal_formatter_loader, locale, ) - .map_err(LoadError::Data)?; + .map_err(PatternLoadError::Data)?; self.load_time_zone_specific_long_names( mz_specific_long_provider, mz_period_provider, @@ -2124,7 +2106,7 @@ impl RawDateTimeNames { fixed_decimal_formatter_loader, locale, ) - .map_err(LoadError::Data)?; + .map_err(PatternLoadError::Data)?; self.load_time_zone_generic_short_names( mz_generic_short_provider, mz_period_provider, @@ -2140,7 +2122,7 @@ impl RawDateTimeNames { fixed_decimal_formatter_loader, locale, ) - .map_err(LoadError::Data)?; + .map_err(PatternLoadError::Data)?; self.load_time_zone_generic_long_names( mz_generic_long_provider, mz_period_provider, @@ -2156,7 +2138,7 @@ impl RawDateTimeNames { fixed_decimal_formatter_loader, locale, ) - .map_err(LoadError::Data)?; + .map_err(PatternLoadError::Data)?; self.load_time_zone_location_names(locations_provider, locale)?; } ResolvedNeoTimeZoneSkeleton::OffsetShort @@ -2166,7 +2148,7 @@ impl RawDateTimeNames { fixed_decimal_formatter_loader, locale, ) - .map_err(LoadError::Data)?; + .map_err(PatternLoadError::Data)?; } ResolvedNeoTimeZoneSkeleton::Isox | ResolvedNeoTimeZoneSkeleton::Isoxx @@ -2229,7 +2211,7 @@ impl RawDateTimeNames { if numeric_field.is_some() { self.load_fixed_decimal_formatter(fixed_decimal_formatter_loader, locale) - .map_err(LoadError::Data)?; + .map_err(PatternLoadError::Data)?; } Ok(()) @@ -2567,7 +2549,8 @@ impl<'data> RawDateTimeNamesBorrowed<'data> { weekday_names .names .get((day as usize) % 7) - .ok_or(GetNameForWeekdayError::Missing) + // TODO: make weekday_names length 7 in the type system + .ok_or(GetNameForWeekdayError::MissingNames(field)) } /// Gets the era symbol, or `None` if data is loaded but symbol isn't found. diff --git a/components/datetime/src/lib.rs b/components/datetime/src/lib.rs index 1d0a4ae5b35..e012f9e1cfe 100644 --- a/components/datetime/src/lib.rs +++ b/components/datetime/src/lib.rs @@ -111,7 +111,7 @@ mod tz_registry; pub use error::MismatchedCalendarError; pub use format::datetime::DateTimeWriteError; -pub use format::neo::{FormattedDateTimePattern, LoadError, SingleLoadError, TypedDateTimeNames}; +pub use format::neo::{FormattedDateTimePattern, PatternLoadError, TypedDateTimeNames}; pub use neo::DateTimeFormatter; pub use neo::FixedCalendarDateTimeFormatter; diff --git a/components/datetime/src/neo.rs b/components/datetime/src/neo.rs index c914fb33ef2..3b6a94d7687 100644 --- a/components/datetime/src/neo.rs +++ b/components/datetime/src/neo.rs @@ -36,7 +36,7 @@ macro_rules! gen_any_buffer_constructors_with_external_loader { provider: &P, locale: &DataLocale, skeleton: $fset, - ) -> Result + ) -> Result where P: AnyProvider + ?Sized, { @@ -54,7 +54,7 @@ macro_rules! gen_any_buffer_constructors_with_external_loader { provider: &P, locale: &DataLocale, skeleton: $fset, - ) -> Result + ) -> Result where P: BufferProvider + ?Sized, { @@ -73,7 +73,7 @@ macro_rules! gen_any_buffer_constructors_with_external_loader { provider: &P, locale: &DataLocale, options: $fset, - ) -> Result + ) -> Result where P: AnyProvider + ?Sized, { @@ -91,7 +91,7 @@ macro_rules! gen_any_buffer_constructors_with_external_loader { provider: &P, locale: &DataLocale, options: $fset, - ) -> Result + ) -> Result where P: BufferProvider + ?Sized, { @@ -197,7 +197,7 @@ where /// ); /// ``` #[cfg(feature = "compiled_data")] - pub fn try_new(locale: &DataLocale, field_set: FSet) -> Result + pub fn try_new(locale: &DataLocale, field_set: FSet) -> Result where crate::provider::Baked: AllFixedCalendarFormattingDataMarkers, { @@ -224,7 +224,7 @@ where provider: &P, locale: &DataLocale, field_set: FSet, - ) -> Result + ) -> Result where P: ?Sized + AllFixedCalendarFormattingDataMarkers @@ -355,7 +355,10 @@ where /// assert_try_writeable_eq!(fmt.format(&dt), "miércoles 4:20 p.m."); /// ``` #[cfg(feature = "compiled_data")] - pub fn try_new_with_skeleton(locale: &DataLocale, skeleton: FSet) -> Result + pub fn try_new_with_skeleton( + locale: &DataLocale, + skeleton: FSet, + ) -> Result where crate::provider::Baked: AllFixedCalendarFormattingDataMarkers, { @@ -382,7 +385,7 @@ where provider: &P, locale: &DataLocale, skeleton: FSet, - ) -> Result + ) -> Result where P: ?Sized + AllFixedCalendarFormattingDataMarkers @@ -410,7 +413,7 @@ where locale: &DataLocale, options: RawNeoOptions, components: NeoComponents, - ) -> Result + ) -> Result where P: ?Sized + AllFixedCalendarFormattingDataMarkers, L: FixedDecimalFormatterLoader, @@ -431,7 +434,7 @@ where components, options, ) - .map_err(LoadError::Data)?; + .map_err(PatternLoadError::Data)?; let mut names = RawDateTimeNames::new_without_number_formatting(); names.load_for_pattern( &>::YearNamesV1Marker::bind(provider), @@ -592,7 +595,7 @@ where /// [`AnyCalendarKind`]: icu_calendar::AnyCalendarKind #[inline(never)] #[cfg(feature = "compiled_data")] - pub fn try_new(locale: &DataLocale, field_set: FSet) -> Result + pub fn try_new(locale: &DataLocale, field_set: FSet) -> Result where crate::provider::Baked: AllAnyCalendarFormattingDataMarkers, { @@ -619,7 +622,7 @@ where provider: &P, locale: &DataLocale, field_set: FSet, - ) -> Result + ) -> Result where P: ?Sized + AllAnyCalendarFormattingDataMarkers + AllAnyCalendarExternalDataMarkers, { @@ -744,7 +747,10 @@ where /// ); /// ``` #[cfg(feature = "compiled_data")] - pub fn try_new_with_skeleton(locale: &DataLocale, skeleton: FSet) -> Result + pub fn try_new_with_skeleton( + locale: &DataLocale, + skeleton: FSet, + ) -> Result where crate::provider::Baked: AllAnyCalendarFormattingDataMarkers, { @@ -771,7 +777,7 @@ where provider: &P, locale: &DataLocale, skeleton: FSet, - ) -> Result + ) -> Result where P: ?Sized + AllAnyCalendarFormattingDataMarkers + AllAnyCalendarExternalDataMarkers, { @@ -797,7 +803,7 @@ where locale: &DataLocale, options: RawNeoOptions, components: NeoComponents, - ) -> Result + ) -> Result where P: ?Sized + AllAnyCalendarFormattingDataMarkers, L: FixedDecimalFormatterLoader + AnyCalendarLoader, @@ -810,7 +816,7 @@ where .and_then(HourCycle::from_locale_value); // END TODO - let calendar = AnyCalendarLoader::load(loader, locale).map_err(LoadError::Data)?; + let calendar = AnyCalendarLoader::load(loader, locale).map_err(PatternLoadError::Data)?; let kind = calendar.kind(); let selection = DateTimeZonePatternSelectionData::try_new_with_skeleton( &AnyCalendarProvider::<::Skel, _>::new(provider, kind), @@ -820,7 +826,7 @@ where components, options, ) - .map_err(LoadError::Data)?; + .map_err(PatternLoadError::Data)?; let mut names = RawDateTimeNames::new_without_number_formatting(); names.load_for_pattern( &AnyCalendarProvider::<::Year, _>::new(provider, kind), diff --git a/components/datetime/src/time_zone.rs b/components/datetime/src/time_zone.rs index 0e750fb4322..b8039a02354 100644 --- a/components/datetime/src/time_zone.rs +++ b/components/datetime/src/time_zone.rs @@ -309,8 +309,8 @@ pub(super) enum TimeZoneFormatterUnit { #[derive(Debug)] pub(super) enum FormatTimeZoneError { - MissingZoneSymbols, - MissingFixedDecimalFormatter, + NamesNotLoaded, + FixedDecimalFormatterNotLoaded, Fallback, MissingInputField(&'static str), } @@ -381,10 +381,10 @@ impl FormatTimeZone for GenericNonLocationFormat { FieldLength::Wide => data_payloads.mz_generic_long.as_ref(), _ => data_payloads.mz_generic_short.as_ref(), }) else { - return Ok(Err(FormatTimeZoneError::MissingZoneSymbols)); + return Ok(Err(FormatTimeZoneError::NamesNotLoaded)); }; let Some(metazone_period) = data_payloads.mz_periods else { - return Ok(Err(FormatTimeZoneError::MissingZoneSymbols)); + return Ok(Err(FormatTimeZoneError::NamesNotLoaded)); }; let Some(name) = names.overrides.get(&time_zone_id).or_else(|| { @@ -428,10 +428,10 @@ impl FormatTimeZone for SpecificNonLocationFormat { FieldLength::Wide => data_payloads.mz_specific_long.as_ref(), _ => data_payloads.mz_specific_short.as_ref(), }) else { - return Ok(Err(FormatTimeZoneError::MissingZoneSymbols)); + return Ok(Err(FormatTimeZoneError::NamesNotLoaded)); }; let Some(metazone_period) = data_payloads.mz_periods else { - return Ok(Err(FormatTimeZoneError::MissingZoneSymbols)); + return Ok(Err(FormatTimeZoneError::NamesNotLoaded)); }; let Some(name) = names @@ -471,10 +471,10 @@ impl FormatTimeZone for LocalizedOffsetFormat { fdf: Option<&FixedDecimalFormatter>, ) -> Result, fmt::Error> { let Some(essentials) = data_payloads.essentials else { - return Ok(Err(FormatTimeZoneError::MissingZoneSymbols)); + return Ok(Err(FormatTimeZoneError::NamesNotLoaded)); }; let Some(fdf) = fdf else { - return Ok(Err(FormatTimeZoneError::MissingFixedDecimalFormatter)); + return Ok(Err(FormatTimeZoneError::FixedDecimalFormatterNotLoaded)); }; let Some(offset) = input.offset else { sink.write_str(&essentials.offset_unknown)?; @@ -563,11 +563,11 @@ impl FormatTimeZone for GenericLocationFormat { }; let Some(locations) = data_payloads.locations else { - return Ok(Err(FormatTimeZoneError::MissingZoneSymbols)); + return Ok(Err(FormatTimeZoneError::NamesNotLoaded)); }; let Some(locations_root) = data_payloads.locations_root else { - return Ok(Err(FormatTimeZoneError::MissingZoneSymbols)); + return Ok(Err(FormatTimeZoneError::NamesNotLoaded)); }; let Some(location) = locations @@ -608,10 +608,10 @@ impl FormatTimeZone for SpecificLocationFormat { return Ok(Err(FormatTimeZoneError::MissingInputField("zone_variant"))); }; let Some(locations) = data_payloads.locations else { - return Ok(Err(FormatTimeZoneError::MissingZoneSymbols)); + return Ok(Err(FormatTimeZoneError::NamesNotLoaded)); }; let Some(locations_root) = data_payloads.locations_root else { - return Ok(Err(FormatTimeZoneError::MissingZoneSymbols)); + return Ok(Err(FormatTimeZoneError::NamesNotLoaded)); }; let Some(location) = locations @@ -656,19 +656,19 @@ impl FormatTimeZone for GenericPartialLocationFormat { }; let Some(locations) = data_payloads.locations else { - return Ok(Err(FormatTimeZoneError::MissingZoneSymbols)); + return Ok(Err(FormatTimeZoneError::NamesNotLoaded)); }; let Some(locations_root) = data_payloads.locations_root else { - return Ok(Err(FormatTimeZoneError::MissingZoneSymbols)); + return Ok(Err(FormatTimeZoneError::NamesNotLoaded)); }; let Some(non_locations) = (match self.0 { FieldLength::Wide => data_payloads.mz_generic_long.as_ref(), _ => data_payloads.mz_generic_short.as_ref(), }) else { - return Ok(Err(FormatTimeZoneError::MissingZoneSymbols)); + return Ok(Err(FormatTimeZoneError::NamesNotLoaded)); }; let Some(metazone_period) = data_payloads.mz_periods else { - return Ok(Err(FormatTimeZoneError::MissingZoneSymbols)); + return Ok(Err(FormatTimeZoneError::NamesNotLoaded)); }; let Some(location) = locations .locations diff --git a/ffi/capi/bindings/c/DateFormatter.h b/ffi/capi/bindings/c/DateFormatter.h index eafa2cbd2db..f1fcc48ccec 100644 --- a/ffi/capi/bindings/c/DateFormatter.h +++ b/ffi/capi/bindings/c/DateFormatter.h @@ -10,11 +10,12 @@ #include "DataProvider.d.h" #include "Date.d.h" #include "DateTime.d.h" +#include "DateTimeFormatError.d.h" #include "DateTimeLength.d.h" -#include "Error.d.h" #include "IsoDate.d.h" #include "IsoDateTime.d.h" #include "Locale.d.h" +#include "PatternLoadError.d.h" #include "DateFormatter.d.h" @@ -23,19 +24,19 @@ -typedef struct icu4x_DateFormatter_create_with_length_mv1_result {union {DateFormatter* ok; Error err;}; bool is_ok;} icu4x_DateFormatter_create_with_length_mv1_result; +typedef struct icu4x_DateFormatter_create_with_length_mv1_result {union {DateFormatter* ok; PatternLoadError err;}; bool is_ok;} icu4x_DateFormatter_create_with_length_mv1_result; icu4x_DateFormatter_create_with_length_mv1_result icu4x_DateFormatter_create_with_length_mv1(const DataProvider* provider, const Locale* locale, DateTimeLength length); -typedef struct icu4x_DateFormatter_format_date_mv1_result {union { Error err;}; bool is_ok;} icu4x_DateFormatter_format_date_mv1_result; +typedef struct icu4x_DateFormatter_format_date_mv1_result {union { DateTimeFormatError err;}; bool is_ok;} icu4x_DateFormatter_format_date_mv1_result; icu4x_DateFormatter_format_date_mv1_result icu4x_DateFormatter_format_date_mv1(const DateFormatter* self, const Date* value, DiplomatWrite* write); -typedef struct icu4x_DateFormatter_format_iso_date_mv1_result {union { Error err;}; bool is_ok;} icu4x_DateFormatter_format_iso_date_mv1_result; +typedef struct icu4x_DateFormatter_format_iso_date_mv1_result {union { DateTimeFormatError err;}; bool is_ok;} icu4x_DateFormatter_format_iso_date_mv1_result; icu4x_DateFormatter_format_iso_date_mv1_result icu4x_DateFormatter_format_iso_date_mv1(const DateFormatter* self, const IsoDate* value, DiplomatWrite* write); -typedef struct icu4x_DateFormatter_format_datetime_mv1_result {union { Error err;}; bool is_ok;} icu4x_DateFormatter_format_datetime_mv1_result; +typedef struct icu4x_DateFormatter_format_datetime_mv1_result {union { DateTimeFormatError err;}; bool is_ok;} icu4x_DateFormatter_format_datetime_mv1_result; icu4x_DateFormatter_format_datetime_mv1_result icu4x_DateFormatter_format_datetime_mv1(const DateFormatter* self, const DateTime* value, DiplomatWrite* write); -typedef struct icu4x_DateFormatter_format_iso_datetime_mv1_result {union { Error err;}; bool is_ok;} icu4x_DateFormatter_format_iso_datetime_mv1_result; +typedef struct icu4x_DateFormatter_format_iso_datetime_mv1_result {union { DateTimeFormatError err;}; bool is_ok;} icu4x_DateFormatter_format_iso_datetime_mv1_result; icu4x_DateFormatter_format_iso_datetime_mv1_result icu4x_DateFormatter_format_iso_datetime_mv1(const DateFormatter* self, const IsoDateTime* value, DiplomatWrite* write); diff --git a/ffi/capi/bindings/c/DateTimeFormatError.d.h b/ffi/capi/bindings/c/DateTimeFormatError.d.h new file mode 100644 index 00000000000..b1ac6c81609 --- /dev/null +++ b/ffi/capi/bindings/c/DateTimeFormatError.d.h @@ -0,0 +1,30 @@ +#ifndef DateTimeFormatError_D_H +#define DateTimeFormatError_D_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + + + + + +typedef enum DateTimeFormatError { + DateTimeFormatError_Unknown = 0, + DateTimeFormatError_MissingInputField = 1, + DateTimeFormatError_ZoneInfoMissingFields = 2, + DateTimeFormatError_InvalidEra = 3, + DateTimeFormatError_InvalidMonthCode = 4, + DateTimeFormatError_InvalidCyclicYear = 5, + DateTimeFormatError_NamesNotLoaded = 16, + DateTimeFormatError_FixedDecimalFormatterNotLoaded = 17, + DateTimeFormatError_UnsupportedField = 18, +} DateTimeFormatError; + +typedef struct DateTimeFormatError_option {union { DateTimeFormatError ok; }; bool is_ok; } DateTimeFormatError_option; + + + +#endif // DateTimeFormatError_D_H diff --git a/ffi/capi/bindings/c/DateTimeFormatError.h b/ffi/capi/bindings/c/DateTimeFormatError.h new file mode 100644 index 00000000000..55a9eccc2d7 --- /dev/null +++ b/ffi/capi/bindings/c/DateTimeFormatError.h @@ -0,0 +1,23 @@ +#ifndef DateTimeFormatError_H +#define DateTimeFormatError_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + + +#include "DateTimeFormatError.d.h" + + + + + + + + + + + +#endif // DateTimeFormatError_H diff --git a/ffi/capi/bindings/c/DateTimeFormatter.h b/ffi/capi/bindings/c/DateTimeFormatter.h index 8d6ca2a4a7a..b3689d3a8c3 100644 --- a/ffi/capi/bindings/c/DateTimeFormatter.h +++ b/ffi/capi/bindings/c/DateTimeFormatter.h @@ -9,10 +9,11 @@ #include "DataProvider.d.h" #include "DateTime.d.h" +#include "DateTimeFormatError.d.h" #include "DateTimeLength.d.h" -#include "Error.d.h" #include "IsoDateTime.d.h" #include "Locale.d.h" +#include "PatternLoadError.d.h" #include "DateTimeFormatter.d.h" @@ -21,13 +22,13 @@ -typedef struct icu4x_DateTimeFormatter_create_with_length_mv1_result {union {DateTimeFormatter* ok; Error err;}; bool is_ok;} icu4x_DateTimeFormatter_create_with_length_mv1_result; +typedef struct icu4x_DateTimeFormatter_create_with_length_mv1_result {union {DateTimeFormatter* ok; PatternLoadError err;}; bool is_ok;} icu4x_DateTimeFormatter_create_with_length_mv1_result; icu4x_DateTimeFormatter_create_with_length_mv1_result icu4x_DateTimeFormatter_create_with_length_mv1(const DataProvider* provider, const Locale* locale, DateTimeLength length); -typedef struct icu4x_DateTimeFormatter_format_datetime_mv1_result {union { Error err;}; bool is_ok;} icu4x_DateTimeFormatter_format_datetime_mv1_result; +typedef struct icu4x_DateTimeFormatter_format_datetime_mv1_result {union { DateTimeFormatError err;}; bool is_ok;} icu4x_DateTimeFormatter_format_datetime_mv1_result; icu4x_DateTimeFormatter_format_datetime_mv1_result icu4x_DateTimeFormatter_format_datetime_mv1(const DateTimeFormatter* self, const DateTime* value, DiplomatWrite* write); -typedef struct icu4x_DateTimeFormatter_format_iso_datetime_mv1_result {union { Error err;}; bool is_ok;} icu4x_DateTimeFormatter_format_iso_datetime_mv1_result; +typedef struct icu4x_DateTimeFormatter_format_iso_datetime_mv1_result {union { DateTimeFormatError err;}; bool is_ok;} icu4x_DateTimeFormatter_format_iso_datetime_mv1_result; icu4x_DateTimeFormatter_format_iso_datetime_mv1_result icu4x_DateTimeFormatter_format_iso_datetime_mv1(const DateTimeFormatter* self, const IsoDateTime* value, DiplomatWrite* write); diff --git a/ffi/capi/bindings/c/Error.d.h b/ffi/capi/bindings/c/Error.d.h deleted file mode 100644 index e57b7c19dc1..00000000000 --- a/ffi/capi/bindings/c/Error.d.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef Error_D_H -#define Error_D_H - -#include -#include -#include -#include -#include "diplomat_runtime.h" - - - - - -typedef enum Error { - Error_UnknownError = 0, - Error_DataMissingDataMarkerError = 256, - Error_DataMissingLocaleError = 258, - Error_DataNeedsLocaleError = 260, - Error_DataExtraneousLocaleError = 261, - Error_DataFilteredResourceError = 262, - Error_DataMismatchedTypeError = 263, - Error_DataCustomError = 266, - Error_DataIoError = 267, - Error_DataUnavailableBufferFormatError = 268, - Error_DateTimePatternError = 2048, - Error_DateTimeMissingInputFieldError = 2049, - Error_DateTimeSkeletonError = 2050, - Error_DateTimeUnsupportedFieldError = 2051, - Error_DateTimeUnsupportedOptionsError = 2052, - Error_DateTimeMissingWeekdaySymbolError = 2053, - Error_DateTimeMissingMonthSymbolError = 2054, - Error_DateTimeFixedDecimalError = 2055, - Error_DateTimeMismatchedCalendarError = 2056, - Error_DateTimeDuplicateFieldError = 2057, - Error_DateTimeTooNarrowError = 2058, - Error_DateTimeMissingNamesError = 2059, - Error_DateTimeZoneInfoMissingFieldsError = 2176, -} Error; - -typedef struct Error_option {union { Error ok; }; bool is_ok; } Error_option; - - - -#endif // Error_D_H diff --git a/ffi/capi/bindings/c/GregorianDateFormatter.h b/ffi/capi/bindings/c/GregorianDateFormatter.h index c2d1aaa3053..b3441486b45 100644 --- a/ffi/capi/bindings/c/GregorianDateFormatter.h +++ b/ffi/capi/bindings/c/GregorianDateFormatter.h @@ -9,10 +9,10 @@ #include "DataProvider.d.h" #include "DateTimeLength.d.h" -#include "Error.d.h" #include "IsoDate.d.h" #include "IsoDateTime.d.h" #include "Locale.d.h" +#include "PatternLoadError.d.h" #include "GregorianDateFormatter.d.h" @@ -21,7 +21,7 @@ -typedef struct icu4x_GregorianDateFormatter_create_with_length_mv1_result {union {GregorianDateFormatter* ok; Error err;}; bool is_ok;} icu4x_GregorianDateFormatter_create_with_length_mv1_result; +typedef struct icu4x_GregorianDateFormatter_create_with_length_mv1_result {union {GregorianDateFormatter* ok; PatternLoadError err;}; bool is_ok;} icu4x_GregorianDateFormatter_create_with_length_mv1_result; icu4x_GregorianDateFormatter_create_with_length_mv1_result icu4x_GregorianDateFormatter_create_with_length_mv1(const DataProvider* provider, const Locale* locale, DateTimeLength length); void icu4x_GregorianDateFormatter_format_iso_date_mv1(const GregorianDateFormatter* self, const IsoDate* value, DiplomatWrite* write); diff --git a/ffi/capi/bindings/c/GregorianDateTimeFormatter.h b/ffi/capi/bindings/c/GregorianDateTimeFormatter.h index acb3236379e..a14057a1395 100644 --- a/ffi/capi/bindings/c/GregorianDateTimeFormatter.h +++ b/ffi/capi/bindings/c/GregorianDateTimeFormatter.h @@ -9,9 +9,9 @@ #include "DataProvider.d.h" #include "DateTimeLength.d.h" -#include "Error.d.h" #include "IsoDateTime.d.h" #include "Locale.d.h" +#include "PatternLoadError.d.h" #include "GregorianDateTimeFormatter.d.h" @@ -20,7 +20,7 @@ -typedef struct icu4x_GregorianDateTimeFormatter_create_with_length_mv1_result {union {GregorianDateTimeFormatter* ok; Error err;}; bool is_ok;} icu4x_GregorianDateTimeFormatter_create_with_length_mv1_result; +typedef struct icu4x_GregorianDateTimeFormatter_create_with_length_mv1_result {union {GregorianDateTimeFormatter* ok; PatternLoadError err;}; bool is_ok;} icu4x_GregorianDateTimeFormatter_create_with_length_mv1_result; icu4x_GregorianDateTimeFormatter_create_with_length_mv1_result icu4x_GregorianDateTimeFormatter_create_with_length_mv1(const DataProvider* provider, const Locale* locale, DateTimeLength length); void icu4x_GregorianDateTimeFormatter_format_iso_datetime_mv1(const GregorianDateTimeFormatter* self, const IsoDateTime* value, DiplomatWrite* write); diff --git a/ffi/capi/bindings/c/GregorianZonedDateTimeFormatter.h b/ffi/capi/bindings/c/GregorianZonedDateTimeFormatter.h index 3c70eb27185..68ea7076e0f 100644 --- a/ffi/capi/bindings/c/GregorianZonedDateTimeFormatter.h +++ b/ffi/capi/bindings/c/GregorianZonedDateTimeFormatter.h @@ -8,10 +8,11 @@ #include "diplomat_runtime.h" #include "DataProvider.d.h" +#include "DateTimeFormatError.d.h" #include "DateTimeLength.d.h" -#include "Error.d.h" #include "IsoDateTime.d.h" #include "Locale.d.h" +#include "PatternLoadError.d.h" #include "TimeZoneInfo.d.h" #include "GregorianZonedDateTimeFormatter.d.h" @@ -21,10 +22,10 @@ -typedef struct icu4x_GregorianZonedDateTimeFormatter_create_with_length_mv1_result {union {GregorianZonedDateTimeFormatter* ok; Error err;}; bool is_ok;} icu4x_GregorianZonedDateTimeFormatter_create_with_length_mv1_result; +typedef struct icu4x_GregorianZonedDateTimeFormatter_create_with_length_mv1_result {union {GregorianZonedDateTimeFormatter* ok; PatternLoadError err;}; bool is_ok;} icu4x_GregorianZonedDateTimeFormatter_create_with_length_mv1_result; icu4x_GregorianZonedDateTimeFormatter_create_with_length_mv1_result icu4x_GregorianZonedDateTimeFormatter_create_with_length_mv1(const DataProvider* provider, const Locale* locale, DateTimeLength length); -typedef struct icu4x_GregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result {union { Error err;}; bool is_ok;} icu4x_GregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result; +typedef struct icu4x_GregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result {union { DateTimeFormatError err;}; bool is_ok;} icu4x_GregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result; icu4x_GregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result icu4x_GregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1(const GregorianZonedDateTimeFormatter* self, const IsoDateTime* datetime, const TimeZoneInfo* time_zone, DiplomatWrite* write); diff --git a/ffi/capi/bindings/c/LocaleCanonicalizer.h b/ffi/capi/bindings/c/LocaleCanonicalizer.h index b4b32fca9b9..5ff475bc331 100644 --- a/ffi/capi/bindings/c/LocaleCanonicalizer.h +++ b/ffi/capi/bindings/c/LocaleCanonicalizer.h @@ -7,8 +7,8 @@ #include #include "diplomat_runtime.h" +#include "DataError.d.h" #include "DataProvider.d.h" -#include "Error.d.h" #include "Locale.d.h" #include "TransformResult.d.h" @@ -19,10 +19,10 @@ -typedef struct icu4x_LocaleCanonicalizer_create_mv1_result {union {LocaleCanonicalizer* ok; Error err;}; bool is_ok;} icu4x_LocaleCanonicalizer_create_mv1_result; +typedef struct icu4x_LocaleCanonicalizer_create_mv1_result {union {LocaleCanonicalizer* ok; DataError err;}; bool is_ok;} icu4x_LocaleCanonicalizer_create_mv1_result; icu4x_LocaleCanonicalizer_create_mv1_result icu4x_LocaleCanonicalizer_create_mv1(const DataProvider* provider); -typedef struct icu4x_LocaleCanonicalizer_create_extended_mv1_result {union {LocaleCanonicalizer* ok; Error err;}; bool is_ok;} icu4x_LocaleCanonicalizer_create_extended_mv1_result; +typedef struct icu4x_LocaleCanonicalizer_create_extended_mv1_result {union {LocaleCanonicalizer* ok; DataError err;}; bool is_ok;} icu4x_LocaleCanonicalizer_create_extended_mv1_result; icu4x_LocaleCanonicalizer_create_extended_mv1_result icu4x_LocaleCanonicalizer_create_extended_mv1(const DataProvider* provider); TransformResult icu4x_LocaleCanonicalizer_canonicalize_mv1(const LocaleCanonicalizer* self, Locale* locale); diff --git a/ffi/capi/bindings/c/LocaleExpander.h b/ffi/capi/bindings/c/LocaleExpander.h index 03bf6539b6f..e18b5414cba 100644 --- a/ffi/capi/bindings/c/LocaleExpander.h +++ b/ffi/capi/bindings/c/LocaleExpander.h @@ -7,8 +7,8 @@ #include #include "diplomat_runtime.h" +#include "DataError.d.h" #include "DataProvider.d.h" -#include "Error.d.h" #include "Locale.d.h" #include "TransformResult.d.h" @@ -19,10 +19,10 @@ -typedef struct icu4x_LocaleExpander_create_mv1_result {union {LocaleExpander* ok; Error err;}; bool is_ok;} icu4x_LocaleExpander_create_mv1_result; +typedef struct icu4x_LocaleExpander_create_mv1_result {union {LocaleExpander* ok; DataError err;}; bool is_ok;} icu4x_LocaleExpander_create_mv1_result; icu4x_LocaleExpander_create_mv1_result icu4x_LocaleExpander_create_mv1(const DataProvider* provider); -typedef struct icu4x_LocaleExpander_create_extended_mv1_result {union {LocaleExpander* ok; Error err;}; bool is_ok;} icu4x_LocaleExpander_create_extended_mv1_result; +typedef struct icu4x_LocaleExpander_create_extended_mv1_result {union {LocaleExpander* ok; DataError err;}; bool is_ok;} icu4x_LocaleExpander_create_extended_mv1_result; icu4x_LocaleExpander_create_extended_mv1_result icu4x_LocaleExpander_create_extended_mv1(const DataProvider* provider); TransformResult icu4x_LocaleExpander_maximize_mv1(const LocaleExpander* self, Locale* locale); diff --git a/ffi/capi/bindings/c/PatternLoadError.d.h b/ffi/capi/bindings/c/PatternLoadError.d.h new file mode 100644 index 00000000000..91b5e67ca08 --- /dev/null +++ b/ffi/capi/bindings/c/PatternLoadError.d.h @@ -0,0 +1,33 @@ +#ifndef PatternLoadError_D_H +#define PatternLoadError_D_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + + + + + +typedef enum PatternLoadError { + PatternLoadError_Unknown = 0, + PatternLoadError_UnsupportedField = 2051, + PatternLoadError_DuplicateField = 2057, + PatternLoadError_TypeTooSpecific = 2058, + PatternLoadError_DataMarkerNotFound = 1, + PatternLoadError_DataIdentifierNotFound = 2, + PatternLoadError_DataInvalidRequest = 3, + PatternLoadError_DataInconsistentData = 4, + PatternLoadError_DataDowncast = 5, + PatternLoadError_DataDeserialize = 6, + PatternLoadError_DataCustom = 7, + PatternLoadError_DataIo = 8, +} PatternLoadError; + +typedef struct PatternLoadError_option {union { PatternLoadError ok; }; bool is_ok; } PatternLoadError_option; + + + +#endif // PatternLoadError_D_H diff --git a/ffi/capi/bindings/c/Error.h b/ffi/capi/bindings/c/PatternLoadError.h similarity index 51% rename from ffi/capi/bindings/c/Error.h rename to ffi/capi/bindings/c/PatternLoadError.h index 6258c5b6a18..573337a0aab 100644 --- a/ffi/capi/bindings/c/Error.h +++ b/ffi/capi/bindings/c/PatternLoadError.h @@ -1,5 +1,5 @@ -#ifndef Error_H -#define Error_H +#ifndef PatternLoadError_H +#define PatternLoadError_H #include #include @@ -8,7 +8,7 @@ #include "diplomat_runtime.h" -#include "Error.d.h" +#include "PatternLoadError.d.h" @@ -20,4 +20,4 @@ -#endif // Error_H +#endif // PatternLoadError_H diff --git a/ffi/capi/bindings/c/TimeFormatter.h b/ffi/capi/bindings/c/TimeFormatter.h index 043137e87d3..a997fcd6b0f 100644 --- a/ffi/capi/bindings/c/TimeFormatter.h +++ b/ffi/capi/bindings/c/TimeFormatter.h @@ -10,9 +10,9 @@ #include "DataProvider.d.h" #include "DateTime.d.h" #include "DateTimeLength.d.h" -#include "Error.d.h" #include "IsoDateTime.d.h" #include "Locale.d.h" +#include "PatternLoadError.d.h" #include "Time.d.h" #include "TimeFormatter.d.h" @@ -22,7 +22,7 @@ -typedef struct icu4x_TimeFormatter_create_with_length_mv1_result {union {TimeFormatter* ok; Error err;}; bool is_ok;} icu4x_TimeFormatter_create_with_length_mv1_result; +typedef struct icu4x_TimeFormatter_create_with_length_mv1_result {union {TimeFormatter* ok; PatternLoadError err;}; bool is_ok;} icu4x_TimeFormatter_create_with_length_mv1_result; icu4x_TimeFormatter_create_with_length_mv1_result icu4x_TimeFormatter_create_with_length_mv1(const DataProvider* provider, const Locale* locale, DateTimeLength length); void icu4x_TimeFormatter_format_time_mv1(const TimeFormatter* self, const Time* value, DiplomatWrite* write); diff --git a/ffi/capi/bindings/c/ZonedDateTimeFormatter.h b/ffi/capi/bindings/c/ZonedDateTimeFormatter.h index 99616873d45..1f9377c7c4b 100644 --- a/ffi/capi/bindings/c/ZonedDateTimeFormatter.h +++ b/ffi/capi/bindings/c/ZonedDateTimeFormatter.h @@ -9,10 +9,11 @@ #include "DataProvider.d.h" #include "DateTime.d.h" +#include "DateTimeFormatError.d.h" #include "DateTimeLength.d.h" -#include "Error.d.h" #include "IsoDateTime.d.h" #include "Locale.d.h" +#include "PatternLoadError.d.h" #include "TimeZoneInfo.d.h" #include "ZonedDateTimeFormatter.d.h" @@ -22,13 +23,13 @@ -typedef struct icu4x_ZonedDateTimeFormatter_create_with_length_mv1_result {union {ZonedDateTimeFormatter* ok; Error err;}; bool is_ok;} icu4x_ZonedDateTimeFormatter_create_with_length_mv1_result; +typedef struct icu4x_ZonedDateTimeFormatter_create_with_length_mv1_result {union {ZonedDateTimeFormatter* ok; PatternLoadError err;}; bool is_ok;} icu4x_ZonedDateTimeFormatter_create_with_length_mv1_result; icu4x_ZonedDateTimeFormatter_create_with_length_mv1_result icu4x_ZonedDateTimeFormatter_create_with_length_mv1(const DataProvider* provider, const Locale* locale, DateTimeLength length); -typedef struct icu4x_ZonedDateTimeFormatter_format_datetime_with_custom_time_zone_mv1_result {union { Error err;}; bool is_ok;} icu4x_ZonedDateTimeFormatter_format_datetime_with_custom_time_zone_mv1_result; +typedef struct icu4x_ZonedDateTimeFormatter_format_datetime_with_custom_time_zone_mv1_result {union { DateTimeFormatError err;}; bool is_ok;} icu4x_ZonedDateTimeFormatter_format_datetime_with_custom_time_zone_mv1_result; icu4x_ZonedDateTimeFormatter_format_datetime_with_custom_time_zone_mv1_result icu4x_ZonedDateTimeFormatter_format_datetime_with_custom_time_zone_mv1(const ZonedDateTimeFormatter* self, const DateTime* datetime, const TimeZoneInfo* time_zone, DiplomatWrite* write); -typedef struct icu4x_ZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result {union { Error err;}; bool is_ok;} icu4x_ZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result; +typedef struct icu4x_ZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result {union { DateTimeFormatError err;}; bool is_ok;} icu4x_ZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result; icu4x_ZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result icu4x_ZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1(const ZonedDateTimeFormatter* self, const IsoDateTime* datetime, const TimeZoneInfo* time_zone, DiplomatWrite* write); diff --git a/ffi/capi/bindings/cpp/icu4x/DateFormatter.d.hpp b/ffi/capi/bindings/cpp/icu4x/DateFormatter.d.hpp index e9173d61abf..9edfc733787 100644 --- a/ffi/capi/bindings/cpp/icu4x/DateFormatter.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/DateFormatter.d.hpp @@ -24,8 +24,9 @@ namespace capi { struct IsoDateTime; } class IsoDateTime; namespace capi { struct Locale; } class Locale; +class DateTimeFormatError; class DateTimeLength; -class Error; +class PatternLoadError; } @@ -39,15 +40,15 @@ namespace icu4x { class DateFormatter { public: - inline static diplomat::result, icu4x::Error> create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length); + inline static diplomat::result, icu4x::PatternLoadError> create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length); - inline diplomat::result format_date(const icu4x::Date& value) const; + inline diplomat::result format_date(const icu4x::Date& value) const; - inline diplomat::result format_iso_date(const icu4x::IsoDate& value) const; + inline diplomat::result format_iso_date(const icu4x::IsoDate& value) const; - inline diplomat::result format_datetime(const icu4x::DateTime& value) const; + inline diplomat::result format_datetime(const icu4x::DateTime& value) const; - inline diplomat::result format_iso_datetime(const icu4x::IsoDateTime& value) const; + inline diplomat::result format_iso_datetime(const icu4x::IsoDateTime& value) const; inline const icu4x::capi::DateFormatter* AsFFI() const; inline icu4x::capi::DateFormatter* AsFFI(); diff --git a/ffi/capi/bindings/cpp/icu4x/DateFormatter.hpp b/ffi/capi/bindings/cpp/icu4x/DateFormatter.hpp index 041d73a6e33..384ebf34ddf 100644 --- a/ffi/capi/bindings/cpp/icu4x/DateFormatter.hpp +++ b/ffi/capi/bindings/cpp/icu4x/DateFormatter.hpp @@ -13,30 +13,31 @@ #include "DataProvider.hpp" #include "Date.hpp" #include "DateTime.hpp" +#include "DateTimeFormatError.hpp" #include "DateTimeLength.hpp" -#include "Error.hpp" #include "IsoDate.hpp" #include "IsoDateTime.hpp" #include "Locale.hpp" +#include "PatternLoadError.hpp" namespace icu4x { namespace capi { extern "C" { - typedef struct icu4x_DateFormatter_create_with_length_mv1_result {union {icu4x::capi::DateFormatter* ok; icu4x::capi::Error err;}; bool is_ok;} icu4x_DateFormatter_create_with_length_mv1_result; + typedef struct icu4x_DateFormatter_create_with_length_mv1_result {union {icu4x::capi::DateFormatter* ok; icu4x::capi::PatternLoadError err;}; bool is_ok;} icu4x_DateFormatter_create_with_length_mv1_result; icu4x_DateFormatter_create_with_length_mv1_result icu4x_DateFormatter_create_with_length_mv1(const icu4x::capi::DataProvider* provider, const icu4x::capi::Locale* locale, icu4x::capi::DateTimeLength length); - typedef struct icu4x_DateFormatter_format_date_mv1_result {union { icu4x::capi::Error err;}; bool is_ok;} icu4x_DateFormatter_format_date_mv1_result; + typedef struct icu4x_DateFormatter_format_date_mv1_result {union { icu4x::capi::DateTimeFormatError err;}; bool is_ok;} icu4x_DateFormatter_format_date_mv1_result; icu4x_DateFormatter_format_date_mv1_result icu4x_DateFormatter_format_date_mv1(const icu4x::capi::DateFormatter* self, const icu4x::capi::Date* value, diplomat::capi::DiplomatWrite* write); - typedef struct icu4x_DateFormatter_format_iso_date_mv1_result {union { icu4x::capi::Error err;}; bool is_ok;} icu4x_DateFormatter_format_iso_date_mv1_result; + typedef struct icu4x_DateFormatter_format_iso_date_mv1_result {union { icu4x::capi::DateTimeFormatError err;}; bool is_ok;} icu4x_DateFormatter_format_iso_date_mv1_result; icu4x_DateFormatter_format_iso_date_mv1_result icu4x_DateFormatter_format_iso_date_mv1(const icu4x::capi::DateFormatter* self, const icu4x::capi::IsoDate* value, diplomat::capi::DiplomatWrite* write); - typedef struct icu4x_DateFormatter_format_datetime_mv1_result {union { icu4x::capi::Error err;}; bool is_ok;} icu4x_DateFormatter_format_datetime_mv1_result; + typedef struct icu4x_DateFormatter_format_datetime_mv1_result {union { icu4x::capi::DateTimeFormatError err;}; bool is_ok;} icu4x_DateFormatter_format_datetime_mv1_result; icu4x_DateFormatter_format_datetime_mv1_result icu4x_DateFormatter_format_datetime_mv1(const icu4x::capi::DateFormatter* self, const icu4x::capi::DateTime* value, diplomat::capi::DiplomatWrite* write); - typedef struct icu4x_DateFormatter_format_iso_datetime_mv1_result {union { icu4x::capi::Error err;}; bool is_ok;} icu4x_DateFormatter_format_iso_datetime_mv1_result; + typedef struct icu4x_DateFormatter_format_iso_datetime_mv1_result {union { icu4x::capi::DateTimeFormatError err;}; bool is_ok;} icu4x_DateFormatter_format_iso_datetime_mv1_result; icu4x_DateFormatter_format_iso_datetime_mv1_result icu4x_DateFormatter_format_iso_datetime_mv1(const icu4x::capi::DateFormatter* self, const icu4x::capi::IsoDateTime* value, diplomat::capi::DiplomatWrite* write); @@ -46,47 +47,47 @@ namespace capi { } // namespace capi } // namespace -inline diplomat::result, icu4x::Error> icu4x::DateFormatter::create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length) { +inline diplomat::result, icu4x::PatternLoadError> icu4x::DateFormatter::create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length) { auto result = icu4x::capi::icu4x_DateFormatter_create_with_length_mv1(provider.AsFFI(), locale.AsFFI(), length.AsFFI()); - return result.is_ok ? diplomat::result, icu4x::Error>(diplomat::Ok>(std::unique_ptr(icu4x::DateFormatter::FromFFI(result.ok)))) : diplomat::result, icu4x::Error>(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result, icu4x::PatternLoadError>(diplomat::Ok>(std::unique_ptr(icu4x::DateFormatter::FromFFI(result.ok)))) : diplomat::result, icu4x::PatternLoadError>(diplomat::Err(icu4x::PatternLoadError::FromFFI(result.err))); } -inline diplomat::result icu4x::DateFormatter::format_date(const icu4x::Date& value) const { +inline diplomat::result icu4x::DateFormatter::format_date(const icu4x::Date& value) const { std::string output; diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); auto result = icu4x::capi::icu4x_DateFormatter_format_date_mv1(this->AsFFI(), value.AsFFI(), &write); - return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::DateTimeFormatError::FromFFI(result.err))); } -inline diplomat::result icu4x::DateFormatter::format_iso_date(const icu4x::IsoDate& value) const { +inline diplomat::result icu4x::DateFormatter::format_iso_date(const icu4x::IsoDate& value) const { std::string output; diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); auto result = icu4x::capi::icu4x_DateFormatter_format_iso_date_mv1(this->AsFFI(), value.AsFFI(), &write); - return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::DateTimeFormatError::FromFFI(result.err))); } -inline diplomat::result icu4x::DateFormatter::format_datetime(const icu4x::DateTime& value) const { +inline diplomat::result icu4x::DateFormatter::format_datetime(const icu4x::DateTime& value) const { std::string output; diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); auto result = icu4x::capi::icu4x_DateFormatter_format_datetime_mv1(this->AsFFI(), value.AsFFI(), &write); - return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::DateTimeFormatError::FromFFI(result.err))); } -inline diplomat::result icu4x::DateFormatter::format_iso_datetime(const icu4x::IsoDateTime& value) const { +inline diplomat::result icu4x::DateFormatter::format_iso_datetime(const icu4x::IsoDateTime& value) const { std::string output; diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); auto result = icu4x::capi::icu4x_DateFormatter_format_iso_datetime_mv1(this->AsFFI(), value.AsFFI(), &write); - return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::DateTimeFormatError::FromFFI(result.err))); } inline const icu4x::capi::DateFormatter* icu4x::DateFormatter::AsFFI() const { diff --git a/ffi/capi/bindings/cpp/icu4x/DateTimeFormatError.d.hpp b/ffi/capi/bindings/cpp/icu4x/DateTimeFormatError.d.hpp new file mode 100644 index 00000000000..3039cb0d8c5 --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/DateTimeFormatError.d.hpp @@ -0,0 +1,60 @@ +#ifndef icu4x_DateTimeFormatError_D_HPP +#define icu4x_DateTimeFormatError_D_HPP + +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" + + +namespace icu4x { +namespace capi { + enum DateTimeFormatError { + DateTimeFormatError_Unknown = 0, + DateTimeFormatError_MissingInputField = 1, + DateTimeFormatError_ZoneInfoMissingFields = 2, + DateTimeFormatError_InvalidEra = 3, + DateTimeFormatError_InvalidMonthCode = 4, + DateTimeFormatError_InvalidCyclicYear = 5, + DateTimeFormatError_NamesNotLoaded = 16, + DateTimeFormatError_FixedDecimalFormatterNotLoaded = 17, + DateTimeFormatError_UnsupportedField = 18, + }; + + typedef struct DateTimeFormatError_option {union { DateTimeFormatError ok; }; bool is_ok; } DateTimeFormatError_option; +} // namespace capi +} // namespace + +namespace icu4x { +class DateTimeFormatError { +public: + enum Value { + Unknown = 0, + MissingInputField = 1, + ZoneInfoMissingFields = 2, + InvalidEra = 3, + InvalidMonthCode = 4, + InvalidCyclicYear = 5, + NamesNotLoaded = 16, + FixedDecimalFormatterNotLoaded = 17, + UnsupportedField = 18, + }; + + DateTimeFormatError() = default; + // Implicit conversions between enum and ::Value + constexpr DateTimeFormatError(Value v) : value(v) {} + constexpr operator Value() const { return value; } + // Prevent usage as boolean value + explicit operator bool() const = delete; + + inline icu4x::capi::DateTimeFormatError AsFFI() const; + inline static icu4x::DateTimeFormatError FromFFI(icu4x::capi::DateTimeFormatError c_enum); +private: + Value value; +}; + +} // namespace +#endif // icu4x_DateTimeFormatError_D_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/DateTimeFormatError.hpp b/ffi/capi/bindings/cpp/icu4x/DateTimeFormatError.hpp new file mode 100644 index 00000000000..5946b07de3b --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/DateTimeFormatError.hpp @@ -0,0 +1,44 @@ +#ifndef icu4x_DateTimeFormatError_HPP +#define icu4x_DateTimeFormatError_HPP + +#include "DateTimeFormatError.d.hpp" + +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" + + +namespace icu4x { +namespace capi { + extern "C" { + + + } // extern "C" +} // namespace capi +} // namespace + +inline icu4x::capi::DateTimeFormatError icu4x::DateTimeFormatError::AsFFI() const { + return static_cast(value); +} + +inline icu4x::DateTimeFormatError icu4x::DateTimeFormatError::FromFFI(icu4x::capi::DateTimeFormatError c_enum) { + switch (c_enum) { + case icu4x::capi::DateTimeFormatError_Unknown: + case icu4x::capi::DateTimeFormatError_MissingInputField: + case icu4x::capi::DateTimeFormatError_ZoneInfoMissingFields: + case icu4x::capi::DateTimeFormatError_InvalidEra: + case icu4x::capi::DateTimeFormatError_InvalidMonthCode: + case icu4x::capi::DateTimeFormatError_InvalidCyclicYear: + case icu4x::capi::DateTimeFormatError_NamesNotLoaded: + case icu4x::capi::DateTimeFormatError_FixedDecimalFormatterNotLoaded: + case icu4x::capi::DateTimeFormatError_UnsupportedField: + return static_cast(c_enum); + default: + abort(); + } +} +#endif // icu4x_DateTimeFormatError_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/DateTimeFormatter.d.hpp b/ffi/capi/bindings/cpp/icu4x/DateTimeFormatter.d.hpp index e9370709e3f..7f461460958 100644 --- a/ffi/capi/bindings/cpp/icu4x/DateTimeFormatter.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/DateTimeFormatter.d.hpp @@ -20,8 +20,9 @@ namespace capi { struct IsoDateTime; } class IsoDateTime; namespace capi { struct Locale; } class Locale; +class DateTimeFormatError; class DateTimeLength; -class Error; +class PatternLoadError; } @@ -35,11 +36,11 @@ namespace icu4x { class DateTimeFormatter { public: - inline static diplomat::result, icu4x::Error> create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length); + inline static diplomat::result, icu4x::PatternLoadError> create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length); - inline diplomat::result format_datetime(const icu4x::DateTime& value) const; + inline diplomat::result format_datetime(const icu4x::DateTime& value) const; - inline diplomat::result format_iso_datetime(const icu4x::IsoDateTime& value) const; + inline diplomat::result format_iso_datetime(const icu4x::IsoDateTime& value) const; inline const icu4x::capi::DateTimeFormatter* AsFFI() const; inline icu4x::capi::DateTimeFormatter* AsFFI(); diff --git a/ffi/capi/bindings/cpp/icu4x/DateTimeFormatter.hpp b/ffi/capi/bindings/cpp/icu4x/DateTimeFormatter.hpp index e89c30ce7a2..7b7aa5fea5a 100644 --- a/ffi/capi/bindings/cpp/icu4x/DateTimeFormatter.hpp +++ b/ffi/capi/bindings/cpp/icu4x/DateTimeFormatter.hpp @@ -12,23 +12,24 @@ #include "../diplomat_runtime.hpp" #include "DataProvider.hpp" #include "DateTime.hpp" +#include "DateTimeFormatError.hpp" #include "DateTimeLength.hpp" -#include "Error.hpp" #include "IsoDateTime.hpp" #include "Locale.hpp" +#include "PatternLoadError.hpp" namespace icu4x { namespace capi { extern "C" { - typedef struct icu4x_DateTimeFormatter_create_with_length_mv1_result {union {icu4x::capi::DateTimeFormatter* ok; icu4x::capi::Error err;}; bool is_ok;} icu4x_DateTimeFormatter_create_with_length_mv1_result; + typedef struct icu4x_DateTimeFormatter_create_with_length_mv1_result {union {icu4x::capi::DateTimeFormatter* ok; icu4x::capi::PatternLoadError err;}; bool is_ok;} icu4x_DateTimeFormatter_create_with_length_mv1_result; icu4x_DateTimeFormatter_create_with_length_mv1_result icu4x_DateTimeFormatter_create_with_length_mv1(const icu4x::capi::DataProvider* provider, const icu4x::capi::Locale* locale, icu4x::capi::DateTimeLength length); - typedef struct icu4x_DateTimeFormatter_format_datetime_mv1_result {union { icu4x::capi::Error err;}; bool is_ok;} icu4x_DateTimeFormatter_format_datetime_mv1_result; + typedef struct icu4x_DateTimeFormatter_format_datetime_mv1_result {union { icu4x::capi::DateTimeFormatError err;}; bool is_ok;} icu4x_DateTimeFormatter_format_datetime_mv1_result; icu4x_DateTimeFormatter_format_datetime_mv1_result icu4x_DateTimeFormatter_format_datetime_mv1(const icu4x::capi::DateTimeFormatter* self, const icu4x::capi::DateTime* value, diplomat::capi::DiplomatWrite* write); - typedef struct icu4x_DateTimeFormatter_format_iso_datetime_mv1_result {union { icu4x::capi::Error err;}; bool is_ok;} icu4x_DateTimeFormatter_format_iso_datetime_mv1_result; + typedef struct icu4x_DateTimeFormatter_format_iso_datetime_mv1_result {union { icu4x::capi::DateTimeFormatError err;}; bool is_ok;} icu4x_DateTimeFormatter_format_iso_datetime_mv1_result; icu4x_DateTimeFormatter_format_iso_datetime_mv1_result icu4x_DateTimeFormatter_format_iso_datetime_mv1(const icu4x::capi::DateTimeFormatter* self, const icu4x::capi::IsoDateTime* value, diplomat::capi::DiplomatWrite* write); @@ -38,29 +39,29 @@ namespace capi { } // namespace capi } // namespace -inline diplomat::result, icu4x::Error> icu4x::DateTimeFormatter::create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length) { +inline diplomat::result, icu4x::PatternLoadError> icu4x::DateTimeFormatter::create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length) { auto result = icu4x::capi::icu4x_DateTimeFormatter_create_with_length_mv1(provider.AsFFI(), locale.AsFFI(), length.AsFFI()); - return result.is_ok ? diplomat::result, icu4x::Error>(diplomat::Ok>(std::unique_ptr(icu4x::DateTimeFormatter::FromFFI(result.ok)))) : diplomat::result, icu4x::Error>(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result, icu4x::PatternLoadError>(diplomat::Ok>(std::unique_ptr(icu4x::DateTimeFormatter::FromFFI(result.ok)))) : diplomat::result, icu4x::PatternLoadError>(diplomat::Err(icu4x::PatternLoadError::FromFFI(result.err))); } -inline diplomat::result icu4x::DateTimeFormatter::format_datetime(const icu4x::DateTime& value) const { +inline diplomat::result icu4x::DateTimeFormatter::format_datetime(const icu4x::DateTime& value) const { std::string output; diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); auto result = icu4x::capi::icu4x_DateTimeFormatter_format_datetime_mv1(this->AsFFI(), value.AsFFI(), &write); - return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::DateTimeFormatError::FromFFI(result.err))); } -inline diplomat::result icu4x::DateTimeFormatter::format_iso_datetime(const icu4x::IsoDateTime& value) const { +inline diplomat::result icu4x::DateTimeFormatter::format_iso_datetime(const icu4x::IsoDateTime& value) const { std::string output; diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); auto result = icu4x::capi::icu4x_DateTimeFormatter_format_iso_datetime_mv1(this->AsFFI(), value.AsFFI(), &write); - return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::DateTimeFormatError::FromFFI(result.err))); } inline const icu4x::capi::DateTimeFormatter* icu4x::DateTimeFormatter::AsFFI() const { diff --git a/ffi/capi/bindings/cpp/icu4x/Error.d.hpp b/ffi/capi/bindings/cpp/icu4x/Error.d.hpp deleted file mode 100644 index 8b7dfcbbc8a..00000000000 --- a/ffi/capi/bindings/cpp/icu4x/Error.d.hpp +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef icu4x_Error_D_HPP -#define icu4x_Error_D_HPP - -#include -#include -#include -#include -#include -#include -#include "../diplomat_runtime.hpp" - - -namespace icu4x { -namespace capi { - enum Error { - Error_UnknownError = 0, - Error_DataMissingDataMarkerError = 256, - Error_DataMissingLocaleError = 258, - Error_DataNeedsLocaleError = 260, - Error_DataExtraneousLocaleError = 261, - Error_DataFilteredResourceError = 262, - Error_DataMismatchedTypeError = 263, - Error_DataCustomError = 266, - Error_DataIoError = 267, - Error_DataUnavailableBufferFormatError = 268, - Error_DateTimePatternError = 2048, - Error_DateTimeMissingInputFieldError = 2049, - Error_DateTimeSkeletonError = 2050, - Error_DateTimeUnsupportedFieldError = 2051, - Error_DateTimeUnsupportedOptionsError = 2052, - Error_DateTimeMissingWeekdaySymbolError = 2053, - Error_DateTimeMissingMonthSymbolError = 2054, - Error_DateTimeFixedDecimalError = 2055, - Error_DateTimeMismatchedCalendarError = 2056, - Error_DateTimeDuplicateFieldError = 2057, - Error_DateTimeTooNarrowError = 2058, - Error_DateTimeMissingNamesError = 2059, - Error_DateTimeZoneInfoMissingFieldsError = 2176, - }; - - typedef struct Error_option {union { Error ok; }; bool is_ok; } Error_option; -} // namespace capi -} // namespace - -namespace icu4x { -class Error { -public: - enum Value { - UnknownError = 0, - DataMissingDataMarkerError = 256, - DataMissingLocaleError = 258, - DataNeedsLocaleError = 260, - DataExtraneousLocaleError = 261, - DataFilteredResourceError = 262, - DataMismatchedTypeError = 263, - DataCustomError = 266, - DataIoError = 267, - DataUnavailableBufferFormatError = 268, - DateTimePatternError = 2048, - DateTimeMissingInputFieldError = 2049, - DateTimeSkeletonError = 2050, - DateTimeUnsupportedFieldError = 2051, - DateTimeUnsupportedOptionsError = 2052, - DateTimeMissingWeekdaySymbolError = 2053, - DateTimeMissingMonthSymbolError = 2054, - DateTimeFixedDecimalError = 2055, - DateTimeMismatchedCalendarError = 2056, - DateTimeDuplicateFieldError = 2057, - DateTimeTooNarrowError = 2058, - DateTimeMissingNamesError = 2059, - DateTimeZoneInfoMissingFieldsError = 2176, - }; - - Error() = default; - // Implicit conversions between enum and ::Value - constexpr Error(Value v) : value(v) {} - constexpr operator Value() const { return value; } - // Prevent usage as boolean value - explicit operator bool() const = delete; - - inline icu4x::capi::Error AsFFI() const; - inline static icu4x::Error FromFFI(icu4x::capi::Error c_enum); -private: - Value value; -}; - -} // namespace -#endif // icu4x_Error_D_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/Error.hpp b/ffi/capi/bindings/cpp/icu4x/Error.hpp deleted file mode 100644 index 375cfedec8b..00000000000 --- a/ffi/capi/bindings/cpp/icu4x/Error.hpp +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef icu4x_Error_HPP -#define icu4x_Error_HPP - -#include "Error.d.hpp" - -#include -#include -#include -#include -#include -#include -#include "../diplomat_runtime.hpp" - - -namespace icu4x { -namespace capi { - extern "C" { - - - } // extern "C" -} // namespace capi -} // namespace - -inline icu4x::capi::Error icu4x::Error::AsFFI() const { - return static_cast(value); -} - -inline icu4x::Error icu4x::Error::FromFFI(icu4x::capi::Error c_enum) { - switch (c_enum) { - case icu4x::capi::Error_UnknownError: - case icu4x::capi::Error_DataMissingDataMarkerError: - case icu4x::capi::Error_DataMissingLocaleError: - case icu4x::capi::Error_DataNeedsLocaleError: - case icu4x::capi::Error_DataExtraneousLocaleError: - case icu4x::capi::Error_DataFilteredResourceError: - case icu4x::capi::Error_DataMismatchedTypeError: - case icu4x::capi::Error_DataCustomError: - case icu4x::capi::Error_DataIoError: - case icu4x::capi::Error_DataUnavailableBufferFormatError: - case icu4x::capi::Error_DateTimePatternError: - case icu4x::capi::Error_DateTimeMissingInputFieldError: - case icu4x::capi::Error_DateTimeSkeletonError: - case icu4x::capi::Error_DateTimeUnsupportedFieldError: - case icu4x::capi::Error_DateTimeUnsupportedOptionsError: - case icu4x::capi::Error_DateTimeMissingWeekdaySymbolError: - case icu4x::capi::Error_DateTimeMissingMonthSymbolError: - case icu4x::capi::Error_DateTimeFixedDecimalError: - case icu4x::capi::Error_DateTimeMismatchedCalendarError: - case icu4x::capi::Error_DateTimeDuplicateFieldError: - case icu4x::capi::Error_DateTimeTooNarrowError: - case icu4x::capi::Error_DateTimeMissingNamesError: - case icu4x::capi::Error_DateTimeZoneInfoMissingFieldsError: - return static_cast(c_enum); - default: - abort(); - } -} -#endif // icu4x_Error_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/GregorianDateFormatter.d.hpp b/ffi/capi/bindings/cpp/icu4x/GregorianDateFormatter.d.hpp index b657e2a0c7e..a11205ea138 100644 --- a/ffi/capi/bindings/cpp/icu4x/GregorianDateFormatter.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/GregorianDateFormatter.d.hpp @@ -21,7 +21,7 @@ class IsoDateTime; namespace capi { struct Locale; } class Locale; class DateTimeLength; -class Error; +class PatternLoadError; } @@ -35,7 +35,7 @@ namespace icu4x { class GregorianDateFormatter { public: - inline static diplomat::result, icu4x::Error> create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length); + inline static diplomat::result, icu4x::PatternLoadError> create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length); inline std::string format_iso_date(const icu4x::IsoDate& value) const; diff --git a/ffi/capi/bindings/cpp/icu4x/GregorianDateFormatter.hpp b/ffi/capi/bindings/cpp/icu4x/GregorianDateFormatter.hpp index 172b867d46e..08ad09a07e0 100644 --- a/ffi/capi/bindings/cpp/icu4x/GregorianDateFormatter.hpp +++ b/ffi/capi/bindings/cpp/icu4x/GregorianDateFormatter.hpp @@ -12,17 +12,17 @@ #include "../diplomat_runtime.hpp" #include "DataProvider.hpp" #include "DateTimeLength.hpp" -#include "Error.hpp" #include "IsoDate.hpp" #include "IsoDateTime.hpp" #include "Locale.hpp" +#include "PatternLoadError.hpp" namespace icu4x { namespace capi { extern "C" { - typedef struct icu4x_GregorianDateFormatter_create_with_length_mv1_result {union {icu4x::capi::GregorianDateFormatter* ok; icu4x::capi::Error err;}; bool is_ok;} icu4x_GregorianDateFormatter_create_with_length_mv1_result; + typedef struct icu4x_GregorianDateFormatter_create_with_length_mv1_result {union {icu4x::capi::GregorianDateFormatter* ok; icu4x::capi::PatternLoadError err;}; bool is_ok;} icu4x_GregorianDateFormatter_create_with_length_mv1_result; icu4x_GregorianDateFormatter_create_with_length_mv1_result icu4x_GregorianDateFormatter_create_with_length_mv1(const icu4x::capi::DataProvider* provider, const icu4x::capi::Locale* locale, icu4x::capi::DateTimeLength length); void icu4x_GregorianDateFormatter_format_iso_date_mv1(const icu4x::capi::GregorianDateFormatter* self, const icu4x::capi::IsoDate* value, diplomat::capi::DiplomatWrite* write); @@ -36,11 +36,11 @@ namespace capi { } // namespace capi } // namespace -inline diplomat::result, icu4x::Error> icu4x::GregorianDateFormatter::create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length) { +inline diplomat::result, icu4x::PatternLoadError> icu4x::GregorianDateFormatter::create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length) { auto result = icu4x::capi::icu4x_GregorianDateFormatter_create_with_length_mv1(provider.AsFFI(), locale.AsFFI(), length.AsFFI()); - return result.is_ok ? diplomat::result, icu4x::Error>(diplomat::Ok>(std::unique_ptr(icu4x::GregorianDateFormatter::FromFFI(result.ok)))) : diplomat::result, icu4x::Error>(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result, icu4x::PatternLoadError>(diplomat::Ok>(std::unique_ptr(icu4x::GregorianDateFormatter::FromFFI(result.ok)))) : diplomat::result, icu4x::PatternLoadError>(diplomat::Err(icu4x::PatternLoadError::FromFFI(result.err))); } inline std::string icu4x::GregorianDateFormatter::format_iso_date(const icu4x::IsoDate& value) const { diff --git a/ffi/capi/bindings/cpp/icu4x/GregorianDateTimeFormatter.d.hpp b/ffi/capi/bindings/cpp/icu4x/GregorianDateTimeFormatter.d.hpp index e40022a0c5a..90d833d349a 100644 --- a/ffi/capi/bindings/cpp/icu4x/GregorianDateTimeFormatter.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/GregorianDateTimeFormatter.d.hpp @@ -19,7 +19,7 @@ class IsoDateTime; namespace capi { struct Locale; } class Locale; class DateTimeLength; -class Error; +class PatternLoadError; } @@ -33,7 +33,7 @@ namespace icu4x { class GregorianDateTimeFormatter { public: - inline static diplomat::result, icu4x::Error> create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length); + inline static diplomat::result, icu4x::PatternLoadError> create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length); inline std::string format_iso_datetime(const icu4x::IsoDateTime& value) const; diff --git a/ffi/capi/bindings/cpp/icu4x/GregorianDateTimeFormatter.hpp b/ffi/capi/bindings/cpp/icu4x/GregorianDateTimeFormatter.hpp index 30ec2246f7e..88c9fd0be8d 100644 --- a/ffi/capi/bindings/cpp/icu4x/GregorianDateTimeFormatter.hpp +++ b/ffi/capi/bindings/cpp/icu4x/GregorianDateTimeFormatter.hpp @@ -12,16 +12,16 @@ #include "../diplomat_runtime.hpp" #include "DataProvider.hpp" #include "DateTimeLength.hpp" -#include "Error.hpp" #include "IsoDateTime.hpp" #include "Locale.hpp" +#include "PatternLoadError.hpp" namespace icu4x { namespace capi { extern "C" { - typedef struct icu4x_GregorianDateTimeFormatter_create_with_length_mv1_result {union {icu4x::capi::GregorianDateTimeFormatter* ok; icu4x::capi::Error err;}; bool is_ok;} icu4x_GregorianDateTimeFormatter_create_with_length_mv1_result; + typedef struct icu4x_GregorianDateTimeFormatter_create_with_length_mv1_result {union {icu4x::capi::GregorianDateTimeFormatter* ok; icu4x::capi::PatternLoadError err;}; bool is_ok;} icu4x_GregorianDateTimeFormatter_create_with_length_mv1_result; icu4x_GregorianDateTimeFormatter_create_with_length_mv1_result icu4x_GregorianDateTimeFormatter_create_with_length_mv1(const icu4x::capi::DataProvider* provider, const icu4x::capi::Locale* locale, icu4x::capi::DateTimeLength length); void icu4x_GregorianDateTimeFormatter_format_iso_datetime_mv1(const icu4x::capi::GregorianDateTimeFormatter* self, const icu4x::capi::IsoDateTime* value, diplomat::capi::DiplomatWrite* write); @@ -33,11 +33,11 @@ namespace capi { } // namespace capi } // namespace -inline diplomat::result, icu4x::Error> icu4x::GregorianDateTimeFormatter::create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length) { +inline diplomat::result, icu4x::PatternLoadError> icu4x::GregorianDateTimeFormatter::create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length) { auto result = icu4x::capi::icu4x_GregorianDateTimeFormatter_create_with_length_mv1(provider.AsFFI(), locale.AsFFI(), length.AsFFI()); - return result.is_ok ? diplomat::result, icu4x::Error>(diplomat::Ok>(std::unique_ptr(icu4x::GregorianDateTimeFormatter::FromFFI(result.ok)))) : diplomat::result, icu4x::Error>(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result, icu4x::PatternLoadError>(diplomat::Ok>(std::unique_ptr(icu4x::GregorianDateTimeFormatter::FromFFI(result.ok)))) : diplomat::result, icu4x::PatternLoadError>(diplomat::Err(icu4x::PatternLoadError::FromFFI(result.err))); } inline std::string icu4x::GregorianDateTimeFormatter::format_iso_datetime(const icu4x::IsoDateTime& value) const { diff --git a/ffi/capi/bindings/cpp/icu4x/GregorianZonedDateTimeFormatter.d.hpp b/ffi/capi/bindings/cpp/icu4x/GregorianZonedDateTimeFormatter.d.hpp index 60bfd736c11..ba02038705d 100644 --- a/ffi/capi/bindings/cpp/icu4x/GregorianZonedDateTimeFormatter.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/GregorianZonedDateTimeFormatter.d.hpp @@ -20,8 +20,9 @@ namespace capi { struct Locale; } class Locale; namespace capi { struct TimeZoneInfo; } class TimeZoneInfo; +class DateTimeFormatError; class DateTimeLength; -class Error; +class PatternLoadError; } @@ -35,9 +36,9 @@ namespace icu4x { class GregorianZonedDateTimeFormatter { public: - inline static diplomat::result, icu4x::Error> create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length); + inline static diplomat::result, icu4x::PatternLoadError> create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length); - inline diplomat::result format_iso_datetime_with_custom_time_zone(const icu4x::IsoDateTime& datetime, const icu4x::TimeZoneInfo& time_zone) const; + inline diplomat::result format_iso_datetime_with_custom_time_zone(const icu4x::IsoDateTime& datetime, const icu4x::TimeZoneInfo& time_zone) const; inline const icu4x::capi::GregorianZonedDateTimeFormatter* AsFFI() const; inline icu4x::capi::GregorianZonedDateTimeFormatter* AsFFI(); diff --git a/ffi/capi/bindings/cpp/icu4x/GregorianZonedDateTimeFormatter.hpp b/ffi/capi/bindings/cpp/icu4x/GregorianZonedDateTimeFormatter.hpp index 06ad6c313a7..801e578cd80 100644 --- a/ffi/capi/bindings/cpp/icu4x/GregorianZonedDateTimeFormatter.hpp +++ b/ffi/capi/bindings/cpp/icu4x/GregorianZonedDateTimeFormatter.hpp @@ -11,10 +11,11 @@ #include #include "../diplomat_runtime.hpp" #include "DataProvider.hpp" +#include "DateTimeFormatError.hpp" #include "DateTimeLength.hpp" -#include "Error.hpp" #include "IsoDateTime.hpp" #include "Locale.hpp" +#include "PatternLoadError.hpp" #include "TimeZoneInfo.hpp" @@ -22,10 +23,10 @@ namespace icu4x { namespace capi { extern "C" { - typedef struct icu4x_GregorianZonedDateTimeFormatter_create_with_length_mv1_result {union {icu4x::capi::GregorianZonedDateTimeFormatter* ok; icu4x::capi::Error err;}; bool is_ok;} icu4x_GregorianZonedDateTimeFormatter_create_with_length_mv1_result; + typedef struct icu4x_GregorianZonedDateTimeFormatter_create_with_length_mv1_result {union {icu4x::capi::GregorianZonedDateTimeFormatter* ok; icu4x::capi::PatternLoadError err;}; bool is_ok;} icu4x_GregorianZonedDateTimeFormatter_create_with_length_mv1_result; icu4x_GregorianZonedDateTimeFormatter_create_with_length_mv1_result icu4x_GregorianZonedDateTimeFormatter_create_with_length_mv1(const icu4x::capi::DataProvider* provider, const icu4x::capi::Locale* locale, icu4x::capi::DateTimeLength length); - typedef struct icu4x_GregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result {union { icu4x::capi::Error err;}; bool is_ok;} icu4x_GregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result; + typedef struct icu4x_GregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result {union { icu4x::capi::DateTimeFormatError err;}; bool is_ok;} icu4x_GregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result; icu4x_GregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result icu4x_GregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1(const icu4x::capi::GregorianZonedDateTimeFormatter* self, const icu4x::capi::IsoDateTime* datetime, const icu4x::capi::TimeZoneInfo* time_zone, diplomat::capi::DiplomatWrite* write); @@ -35,21 +36,21 @@ namespace capi { } // namespace capi } // namespace -inline diplomat::result, icu4x::Error> icu4x::GregorianZonedDateTimeFormatter::create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length) { +inline diplomat::result, icu4x::PatternLoadError> icu4x::GregorianZonedDateTimeFormatter::create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length) { auto result = icu4x::capi::icu4x_GregorianZonedDateTimeFormatter_create_with_length_mv1(provider.AsFFI(), locale.AsFFI(), length.AsFFI()); - return result.is_ok ? diplomat::result, icu4x::Error>(diplomat::Ok>(std::unique_ptr(icu4x::GregorianZonedDateTimeFormatter::FromFFI(result.ok)))) : diplomat::result, icu4x::Error>(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result, icu4x::PatternLoadError>(diplomat::Ok>(std::unique_ptr(icu4x::GregorianZonedDateTimeFormatter::FromFFI(result.ok)))) : diplomat::result, icu4x::PatternLoadError>(diplomat::Err(icu4x::PatternLoadError::FromFFI(result.err))); } -inline diplomat::result icu4x::GregorianZonedDateTimeFormatter::format_iso_datetime_with_custom_time_zone(const icu4x::IsoDateTime& datetime, const icu4x::TimeZoneInfo& time_zone) const { +inline diplomat::result icu4x::GregorianZonedDateTimeFormatter::format_iso_datetime_with_custom_time_zone(const icu4x::IsoDateTime& datetime, const icu4x::TimeZoneInfo& time_zone) const { std::string output; diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); auto result = icu4x::capi::icu4x_GregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1(this->AsFFI(), datetime.AsFFI(), time_zone.AsFFI(), &write); - return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::DateTimeFormatError::FromFFI(result.err))); } inline const icu4x::capi::GregorianZonedDateTimeFormatter* icu4x::GregorianZonedDateTimeFormatter::AsFFI() const { diff --git a/ffi/capi/bindings/cpp/icu4x/LocaleCanonicalizer.d.hpp b/ffi/capi/bindings/cpp/icu4x/LocaleCanonicalizer.d.hpp index 771f016af1a..1e0da62d1c5 100644 --- a/ffi/capi/bindings/cpp/icu4x/LocaleCanonicalizer.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/LocaleCanonicalizer.d.hpp @@ -16,7 +16,7 @@ namespace capi { struct Locale; } class Locale; namespace capi { struct LocaleCanonicalizer; } class LocaleCanonicalizer; -class Error; +class DataError; class TransformResult; } @@ -31,9 +31,9 @@ namespace icu4x { class LocaleCanonicalizer { public: - inline static diplomat::result, icu4x::Error> create(const icu4x::DataProvider& provider); + inline static diplomat::result, icu4x::DataError> create(const icu4x::DataProvider& provider); - inline static diplomat::result, icu4x::Error> create_extended(const icu4x::DataProvider& provider); + inline static diplomat::result, icu4x::DataError> create_extended(const icu4x::DataProvider& provider); inline icu4x::TransformResult canonicalize(icu4x::Locale& locale) const; diff --git a/ffi/capi/bindings/cpp/icu4x/LocaleCanonicalizer.hpp b/ffi/capi/bindings/cpp/icu4x/LocaleCanonicalizer.hpp index b1d73b59d05..b8df539a223 100644 --- a/ffi/capi/bindings/cpp/icu4x/LocaleCanonicalizer.hpp +++ b/ffi/capi/bindings/cpp/icu4x/LocaleCanonicalizer.hpp @@ -10,8 +10,8 @@ #include #include #include "../diplomat_runtime.hpp" +#include "DataError.hpp" #include "DataProvider.hpp" -#include "Error.hpp" #include "Locale.hpp" #include "TransformResult.hpp" @@ -20,10 +20,10 @@ namespace icu4x { namespace capi { extern "C" { - typedef struct icu4x_LocaleCanonicalizer_create_mv1_result {union {icu4x::capi::LocaleCanonicalizer* ok; icu4x::capi::Error err;}; bool is_ok;} icu4x_LocaleCanonicalizer_create_mv1_result; + typedef struct icu4x_LocaleCanonicalizer_create_mv1_result {union {icu4x::capi::LocaleCanonicalizer* ok; icu4x::capi::DataError err;}; bool is_ok;} icu4x_LocaleCanonicalizer_create_mv1_result; icu4x_LocaleCanonicalizer_create_mv1_result icu4x_LocaleCanonicalizer_create_mv1(const icu4x::capi::DataProvider* provider); - typedef struct icu4x_LocaleCanonicalizer_create_extended_mv1_result {union {icu4x::capi::LocaleCanonicalizer* ok; icu4x::capi::Error err;}; bool is_ok;} icu4x_LocaleCanonicalizer_create_extended_mv1_result; + typedef struct icu4x_LocaleCanonicalizer_create_extended_mv1_result {union {icu4x::capi::LocaleCanonicalizer* ok; icu4x::capi::DataError err;}; bool is_ok;} icu4x_LocaleCanonicalizer_create_extended_mv1_result; icu4x_LocaleCanonicalizer_create_extended_mv1_result icu4x_LocaleCanonicalizer_create_extended_mv1(const icu4x::capi::DataProvider* provider); icu4x::capi::TransformResult icu4x_LocaleCanonicalizer_canonicalize_mv1(const icu4x::capi::LocaleCanonicalizer* self, icu4x::capi::Locale* locale); @@ -35,14 +35,14 @@ namespace capi { } // namespace capi } // namespace -inline diplomat::result, icu4x::Error> icu4x::LocaleCanonicalizer::create(const icu4x::DataProvider& provider) { +inline diplomat::result, icu4x::DataError> icu4x::LocaleCanonicalizer::create(const icu4x::DataProvider& provider) { auto result = icu4x::capi::icu4x_LocaleCanonicalizer_create_mv1(provider.AsFFI()); - return result.is_ok ? diplomat::result, icu4x::Error>(diplomat::Ok>(std::unique_ptr(icu4x::LocaleCanonicalizer::FromFFI(result.ok)))) : diplomat::result, icu4x::Error>(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result, icu4x::DataError>(diplomat::Ok>(std::unique_ptr(icu4x::LocaleCanonicalizer::FromFFI(result.ok)))) : diplomat::result, icu4x::DataError>(diplomat::Err(icu4x::DataError::FromFFI(result.err))); } -inline diplomat::result, icu4x::Error> icu4x::LocaleCanonicalizer::create_extended(const icu4x::DataProvider& provider) { +inline diplomat::result, icu4x::DataError> icu4x::LocaleCanonicalizer::create_extended(const icu4x::DataProvider& provider) { auto result = icu4x::capi::icu4x_LocaleCanonicalizer_create_extended_mv1(provider.AsFFI()); - return result.is_ok ? diplomat::result, icu4x::Error>(diplomat::Ok>(std::unique_ptr(icu4x::LocaleCanonicalizer::FromFFI(result.ok)))) : diplomat::result, icu4x::Error>(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result, icu4x::DataError>(diplomat::Ok>(std::unique_ptr(icu4x::LocaleCanonicalizer::FromFFI(result.ok)))) : diplomat::result, icu4x::DataError>(diplomat::Err(icu4x::DataError::FromFFI(result.err))); } inline icu4x::TransformResult icu4x::LocaleCanonicalizer::canonicalize(icu4x::Locale& locale) const { diff --git a/ffi/capi/bindings/cpp/icu4x/LocaleExpander.d.hpp b/ffi/capi/bindings/cpp/icu4x/LocaleExpander.d.hpp index 11934c115b9..39770d9c1c1 100644 --- a/ffi/capi/bindings/cpp/icu4x/LocaleExpander.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/LocaleExpander.d.hpp @@ -16,7 +16,7 @@ namespace capi { struct Locale; } class Locale; namespace capi { struct LocaleExpander; } class LocaleExpander; -class Error; +class DataError; class TransformResult; } @@ -31,9 +31,9 @@ namespace icu4x { class LocaleExpander { public: - inline static diplomat::result, icu4x::Error> create(const icu4x::DataProvider& provider); + inline static diplomat::result, icu4x::DataError> create(const icu4x::DataProvider& provider); - inline static diplomat::result, icu4x::Error> create_extended(const icu4x::DataProvider& provider); + inline static diplomat::result, icu4x::DataError> create_extended(const icu4x::DataProvider& provider); inline icu4x::TransformResult maximize(icu4x::Locale& locale) const; diff --git a/ffi/capi/bindings/cpp/icu4x/LocaleExpander.hpp b/ffi/capi/bindings/cpp/icu4x/LocaleExpander.hpp index 4bdcb01ece9..aa14c1468cc 100644 --- a/ffi/capi/bindings/cpp/icu4x/LocaleExpander.hpp +++ b/ffi/capi/bindings/cpp/icu4x/LocaleExpander.hpp @@ -10,8 +10,8 @@ #include #include #include "../diplomat_runtime.hpp" +#include "DataError.hpp" #include "DataProvider.hpp" -#include "Error.hpp" #include "Locale.hpp" #include "TransformResult.hpp" @@ -20,10 +20,10 @@ namespace icu4x { namespace capi { extern "C" { - typedef struct icu4x_LocaleExpander_create_mv1_result {union {icu4x::capi::LocaleExpander* ok; icu4x::capi::Error err;}; bool is_ok;} icu4x_LocaleExpander_create_mv1_result; + typedef struct icu4x_LocaleExpander_create_mv1_result {union {icu4x::capi::LocaleExpander* ok; icu4x::capi::DataError err;}; bool is_ok;} icu4x_LocaleExpander_create_mv1_result; icu4x_LocaleExpander_create_mv1_result icu4x_LocaleExpander_create_mv1(const icu4x::capi::DataProvider* provider); - typedef struct icu4x_LocaleExpander_create_extended_mv1_result {union {icu4x::capi::LocaleExpander* ok; icu4x::capi::Error err;}; bool is_ok;} icu4x_LocaleExpander_create_extended_mv1_result; + typedef struct icu4x_LocaleExpander_create_extended_mv1_result {union {icu4x::capi::LocaleExpander* ok; icu4x::capi::DataError err;}; bool is_ok;} icu4x_LocaleExpander_create_extended_mv1_result; icu4x_LocaleExpander_create_extended_mv1_result icu4x_LocaleExpander_create_extended_mv1(const icu4x::capi::DataProvider* provider); icu4x::capi::TransformResult icu4x_LocaleExpander_maximize_mv1(const icu4x::capi::LocaleExpander* self, icu4x::capi::Locale* locale); @@ -39,14 +39,14 @@ namespace capi { } // namespace capi } // namespace -inline diplomat::result, icu4x::Error> icu4x::LocaleExpander::create(const icu4x::DataProvider& provider) { +inline diplomat::result, icu4x::DataError> icu4x::LocaleExpander::create(const icu4x::DataProvider& provider) { auto result = icu4x::capi::icu4x_LocaleExpander_create_mv1(provider.AsFFI()); - return result.is_ok ? diplomat::result, icu4x::Error>(diplomat::Ok>(std::unique_ptr(icu4x::LocaleExpander::FromFFI(result.ok)))) : diplomat::result, icu4x::Error>(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result, icu4x::DataError>(diplomat::Ok>(std::unique_ptr(icu4x::LocaleExpander::FromFFI(result.ok)))) : diplomat::result, icu4x::DataError>(diplomat::Err(icu4x::DataError::FromFFI(result.err))); } -inline diplomat::result, icu4x::Error> icu4x::LocaleExpander::create_extended(const icu4x::DataProvider& provider) { +inline diplomat::result, icu4x::DataError> icu4x::LocaleExpander::create_extended(const icu4x::DataProvider& provider) { auto result = icu4x::capi::icu4x_LocaleExpander_create_extended_mv1(provider.AsFFI()); - return result.is_ok ? diplomat::result, icu4x::Error>(diplomat::Ok>(std::unique_ptr(icu4x::LocaleExpander::FromFFI(result.ok)))) : diplomat::result, icu4x::Error>(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result, icu4x::DataError>(diplomat::Ok>(std::unique_ptr(icu4x::LocaleExpander::FromFFI(result.ok)))) : diplomat::result, icu4x::DataError>(diplomat::Err(icu4x::DataError::FromFFI(result.err))); } inline icu4x::TransformResult icu4x::LocaleExpander::maximize(icu4x::Locale& locale) const { diff --git a/ffi/capi/bindings/cpp/icu4x/PatternLoadError.d.hpp b/ffi/capi/bindings/cpp/icu4x/PatternLoadError.d.hpp new file mode 100644 index 00000000000..f00f37e0419 --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/PatternLoadError.d.hpp @@ -0,0 +1,66 @@ +#ifndef icu4x_PatternLoadError_D_HPP +#define icu4x_PatternLoadError_D_HPP + +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" + + +namespace icu4x { +namespace capi { + enum PatternLoadError { + PatternLoadError_Unknown = 0, + PatternLoadError_UnsupportedField = 2051, + PatternLoadError_DuplicateField = 2057, + PatternLoadError_TypeTooSpecific = 2058, + PatternLoadError_DataMarkerNotFound = 1, + PatternLoadError_DataIdentifierNotFound = 2, + PatternLoadError_DataInvalidRequest = 3, + PatternLoadError_DataInconsistentData = 4, + PatternLoadError_DataDowncast = 5, + PatternLoadError_DataDeserialize = 6, + PatternLoadError_DataCustom = 7, + PatternLoadError_DataIo = 8, + }; + + typedef struct PatternLoadError_option {union { PatternLoadError ok; }; bool is_ok; } PatternLoadError_option; +} // namespace capi +} // namespace + +namespace icu4x { +class PatternLoadError { +public: + enum Value { + Unknown = 0, + UnsupportedField = 2051, + DuplicateField = 2057, + TypeTooSpecific = 2058, + DataMarkerNotFound = 1, + DataIdentifierNotFound = 2, + DataInvalidRequest = 3, + DataInconsistentData = 4, + DataDowncast = 5, + DataDeserialize = 6, + DataCustom = 7, + DataIo = 8, + }; + + PatternLoadError() = default; + // Implicit conversions between enum and ::Value + constexpr PatternLoadError(Value v) : value(v) {} + constexpr operator Value() const { return value; } + // Prevent usage as boolean value + explicit operator bool() const = delete; + + inline icu4x::capi::PatternLoadError AsFFI() const; + inline static icu4x::PatternLoadError FromFFI(icu4x::capi::PatternLoadError c_enum); +private: + Value value; +}; + +} // namespace +#endif // icu4x_PatternLoadError_D_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/PatternLoadError.hpp b/ffi/capi/bindings/cpp/icu4x/PatternLoadError.hpp new file mode 100644 index 00000000000..a3e40b2365a --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/PatternLoadError.hpp @@ -0,0 +1,47 @@ +#ifndef icu4x_PatternLoadError_HPP +#define icu4x_PatternLoadError_HPP + +#include "PatternLoadError.d.hpp" + +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" + + +namespace icu4x { +namespace capi { + extern "C" { + + + } // extern "C" +} // namespace capi +} // namespace + +inline icu4x::capi::PatternLoadError icu4x::PatternLoadError::AsFFI() const { + return static_cast(value); +} + +inline icu4x::PatternLoadError icu4x::PatternLoadError::FromFFI(icu4x::capi::PatternLoadError c_enum) { + switch (c_enum) { + case icu4x::capi::PatternLoadError_Unknown: + case icu4x::capi::PatternLoadError_UnsupportedField: + case icu4x::capi::PatternLoadError_DuplicateField: + case icu4x::capi::PatternLoadError_TypeTooSpecific: + case icu4x::capi::PatternLoadError_DataMarkerNotFound: + case icu4x::capi::PatternLoadError_DataIdentifierNotFound: + case icu4x::capi::PatternLoadError_DataInvalidRequest: + case icu4x::capi::PatternLoadError_DataInconsistentData: + case icu4x::capi::PatternLoadError_DataDowncast: + case icu4x::capi::PatternLoadError_DataDeserialize: + case icu4x::capi::PatternLoadError_DataCustom: + case icu4x::capi::PatternLoadError_DataIo: + return static_cast(c_enum); + default: + abort(); + } +} +#endif // icu4x_PatternLoadError_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/TimeFormatter.d.hpp b/ffi/capi/bindings/cpp/icu4x/TimeFormatter.d.hpp index 041bd1d89e3..4053669bfa6 100644 --- a/ffi/capi/bindings/cpp/icu4x/TimeFormatter.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/TimeFormatter.d.hpp @@ -23,7 +23,7 @@ class Time; namespace capi { struct TimeFormatter; } class TimeFormatter; class DateTimeLength; -class Error; +class PatternLoadError; } @@ -37,7 +37,7 @@ namespace icu4x { class TimeFormatter { public: - inline static diplomat::result, icu4x::Error> create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length); + inline static diplomat::result, icu4x::PatternLoadError> create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length); inline std::string format_time(const icu4x::Time& value) const; diff --git a/ffi/capi/bindings/cpp/icu4x/TimeFormatter.hpp b/ffi/capi/bindings/cpp/icu4x/TimeFormatter.hpp index beb016b3443..a79bd11c28f 100644 --- a/ffi/capi/bindings/cpp/icu4x/TimeFormatter.hpp +++ b/ffi/capi/bindings/cpp/icu4x/TimeFormatter.hpp @@ -13,9 +13,9 @@ #include "DataProvider.hpp" #include "DateTime.hpp" #include "DateTimeLength.hpp" -#include "Error.hpp" #include "IsoDateTime.hpp" #include "Locale.hpp" +#include "PatternLoadError.hpp" #include "Time.hpp" @@ -23,7 +23,7 @@ namespace icu4x { namespace capi { extern "C" { - typedef struct icu4x_TimeFormatter_create_with_length_mv1_result {union {icu4x::capi::TimeFormatter* ok; icu4x::capi::Error err;}; bool is_ok;} icu4x_TimeFormatter_create_with_length_mv1_result; + typedef struct icu4x_TimeFormatter_create_with_length_mv1_result {union {icu4x::capi::TimeFormatter* ok; icu4x::capi::PatternLoadError err;}; bool is_ok;} icu4x_TimeFormatter_create_with_length_mv1_result; icu4x_TimeFormatter_create_with_length_mv1_result icu4x_TimeFormatter_create_with_length_mv1(const icu4x::capi::DataProvider* provider, const icu4x::capi::Locale* locale, icu4x::capi::DateTimeLength length); void icu4x_TimeFormatter_format_time_mv1(const icu4x::capi::TimeFormatter* self, const icu4x::capi::Time* value, diplomat::capi::DiplomatWrite* write); @@ -39,11 +39,11 @@ namespace capi { } // namespace capi } // namespace -inline diplomat::result, icu4x::Error> icu4x::TimeFormatter::create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length) { +inline diplomat::result, icu4x::PatternLoadError> icu4x::TimeFormatter::create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length) { auto result = icu4x::capi::icu4x_TimeFormatter_create_with_length_mv1(provider.AsFFI(), locale.AsFFI(), length.AsFFI()); - return result.is_ok ? diplomat::result, icu4x::Error>(diplomat::Ok>(std::unique_ptr(icu4x::TimeFormatter::FromFFI(result.ok)))) : diplomat::result, icu4x::Error>(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result, icu4x::PatternLoadError>(diplomat::Ok>(std::unique_ptr(icu4x::TimeFormatter::FromFFI(result.ok)))) : diplomat::result, icu4x::PatternLoadError>(diplomat::Err(icu4x::PatternLoadError::FromFFI(result.err))); } inline std::string icu4x::TimeFormatter::format_time(const icu4x::Time& value) const { diff --git a/ffi/capi/bindings/cpp/icu4x/ZonedDateTimeFormatter.d.hpp b/ffi/capi/bindings/cpp/icu4x/ZonedDateTimeFormatter.d.hpp index a5d7731ac96..3f861671528 100644 --- a/ffi/capi/bindings/cpp/icu4x/ZonedDateTimeFormatter.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/ZonedDateTimeFormatter.d.hpp @@ -22,8 +22,9 @@ namespace capi { struct TimeZoneInfo; } class TimeZoneInfo; namespace capi { struct ZonedDateTimeFormatter; } class ZonedDateTimeFormatter; +class DateTimeFormatError; class DateTimeLength; -class Error; +class PatternLoadError; } @@ -37,11 +38,11 @@ namespace icu4x { class ZonedDateTimeFormatter { public: - inline static diplomat::result, icu4x::Error> create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length); + inline static diplomat::result, icu4x::PatternLoadError> create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length); - inline diplomat::result format_datetime_with_custom_time_zone(const icu4x::DateTime& datetime, const icu4x::TimeZoneInfo& time_zone) const; + inline diplomat::result format_datetime_with_custom_time_zone(const icu4x::DateTime& datetime, const icu4x::TimeZoneInfo& time_zone) const; - inline diplomat::result format_iso_datetime_with_custom_time_zone(const icu4x::IsoDateTime& datetime, const icu4x::TimeZoneInfo& time_zone) const; + inline diplomat::result format_iso_datetime_with_custom_time_zone(const icu4x::IsoDateTime& datetime, const icu4x::TimeZoneInfo& time_zone) const; inline const icu4x::capi::ZonedDateTimeFormatter* AsFFI() const; inline icu4x::capi::ZonedDateTimeFormatter* AsFFI(); diff --git a/ffi/capi/bindings/cpp/icu4x/ZonedDateTimeFormatter.hpp b/ffi/capi/bindings/cpp/icu4x/ZonedDateTimeFormatter.hpp index 6cb0ed80c62..8923a1297cb 100644 --- a/ffi/capi/bindings/cpp/icu4x/ZonedDateTimeFormatter.hpp +++ b/ffi/capi/bindings/cpp/icu4x/ZonedDateTimeFormatter.hpp @@ -12,10 +12,11 @@ #include "../diplomat_runtime.hpp" #include "DataProvider.hpp" #include "DateTime.hpp" +#include "DateTimeFormatError.hpp" #include "DateTimeLength.hpp" -#include "Error.hpp" #include "IsoDateTime.hpp" #include "Locale.hpp" +#include "PatternLoadError.hpp" #include "TimeZoneInfo.hpp" @@ -23,13 +24,13 @@ namespace icu4x { namespace capi { extern "C" { - typedef struct icu4x_ZonedDateTimeFormatter_create_with_length_mv1_result {union {icu4x::capi::ZonedDateTimeFormatter* ok; icu4x::capi::Error err;}; bool is_ok;} icu4x_ZonedDateTimeFormatter_create_with_length_mv1_result; + typedef struct icu4x_ZonedDateTimeFormatter_create_with_length_mv1_result {union {icu4x::capi::ZonedDateTimeFormatter* ok; icu4x::capi::PatternLoadError err;}; bool is_ok;} icu4x_ZonedDateTimeFormatter_create_with_length_mv1_result; icu4x_ZonedDateTimeFormatter_create_with_length_mv1_result icu4x_ZonedDateTimeFormatter_create_with_length_mv1(const icu4x::capi::DataProvider* provider, const icu4x::capi::Locale* locale, icu4x::capi::DateTimeLength length); - typedef struct icu4x_ZonedDateTimeFormatter_format_datetime_with_custom_time_zone_mv1_result {union { icu4x::capi::Error err;}; bool is_ok;} icu4x_ZonedDateTimeFormatter_format_datetime_with_custom_time_zone_mv1_result; + typedef struct icu4x_ZonedDateTimeFormatter_format_datetime_with_custom_time_zone_mv1_result {union { icu4x::capi::DateTimeFormatError err;}; bool is_ok;} icu4x_ZonedDateTimeFormatter_format_datetime_with_custom_time_zone_mv1_result; icu4x_ZonedDateTimeFormatter_format_datetime_with_custom_time_zone_mv1_result icu4x_ZonedDateTimeFormatter_format_datetime_with_custom_time_zone_mv1(const icu4x::capi::ZonedDateTimeFormatter* self, const icu4x::capi::DateTime* datetime, const icu4x::capi::TimeZoneInfo* time_zone, diplomat::capi::DiplomatWrite* write); - typedef struct icu4x_ZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result {union { icu4x::capi::Error err;}; bool is_ok;} icu4x_ZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result; + typedef struct icu4x_ZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result {union { icu4x::capi::DateTimeFormatError err;}; bool is_ok;} icu4x_ZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result; icu4x_ZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1_result icu4x_ZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1(const icu4x::capi::ZonedDateTimeFormatter* self, const icu4x::capi::IsoDateTime* datetime, const icu4x::capi::TimeZoneInfo* time_zone, diplomat::capi::DiplomatWrite* write); @@ -39,31 +40,31 @@ namespace capi { } // namespace capi } // namespace -inline diplomat::result, icu4x::Error> icu4x::ZonedDateTimeFormatter::create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length) { +inline diplomat::result, icu4x::PatternLoadError> icu4x::ZonedDateTimeFormatter::create_with_length(const icu4x::DataProvider& provider, const icu4x::Locale& locale, icu4x::DateTimeLength length) { auto result = icu4x::capi::icu4x_ZonedDateTimeFormatter_create_with_length_mv1(provider.AsFFI(), locale.AsFFI(), length.AsFFI()); - return result.is_ok ? diplomat::result, icu4x::Error>(diplomat::Ok>(std::unique_ptr(icu4x::ZonedDateTimeFormatter::FromFFI(result.ok)))) : diplomat::result, icu4x::Error>(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result, icu4x::PatternLoadError>(diplomat::Ok>(std::unique_ptr(icu4x::ZonedDateTimeFormatter::FromFFI(result.ok)))) : diplomat::result, icu4x::PatternLoadError>(diplomat::Err(icu4x::PatternLoadError::FromFFI(result.err))); } -inline diplomat::result icu4x::ZonedDateTimeFormatter::format_datetime_with_custom_time_zone(const icu4x::DateTime& datetime, const icu4x::TimeZoneInfo& time_zone) const { +inline diplomat::result icu4x::ZonedDateTimeFormatter::format_datetime_with_custom_time_zone(const icu4x::DateTime& datetime, const icu4x::TimeZoneInfo& time_zone) const { std::string output; diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); auto result = icu4x::capi::icu4x_ZonedDateTimeFormatter_format_datetime_with_custom_time_zone_mv1(this->AsFFI(), datetime.AsFFI(), time_zone.AsFFI(), &write); - return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::DateTimeFormatError::FromFFI(result.err))); } -inline diplomat::result icu4x::ZonedDateTimeFormatter::format_iso_datetime_with_custom_time_zone(const icu4x::IsoDateTime& datetime, const icu4x::TimeZoneInfo& time_zone) const { +inline diplomat::result icu4x::ZonedDateTimeFormatter::format_iso_datetime_with_custom_time_zone(const icu4x::IsoDateTime& datetime, const icu4x::TimeZoneInfo& time_zone) const { std::string output; diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); auto result = icu4x::capi::icu4x_ZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1(this->AsFFI(), datetime.AsFFI(), time_zone.AsFFI(), &write); - return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::Error::FromFFI(result.err))); + return result.is_ok ? diplomat::result(diplomat::Ok(std::move(output))) : diplomat::result(diplomat::Err(icu4x::DateTimeFormatError::FromFFI(result.err))); } inline const icu4x::capi::ZonedDateTimeFormatter* icu4x::ZonedDateTimeFormatter::AsFFI() const { diff --git a/ffi/capi/bindings/dart/DateFormatter.g.dart b/ffi/capi/bindings/dart/DateFormatter.g.dart index a44162b4dba..be16f83a0ab 100644 --- a/ffi/capi/bindings/dart/DateFormatter.g.dart +++ b/ffi/capi/bindings/dart/DateFormatter.g.dart @@ -27,23 +27,23 @@ final class DateFormatter implements ffi.Finalizable { /// Creates a new [`DateFormatter`] from locale data. /// - /// Throws [Error] on failure. + /// Throws [PatternLoadError] on failure. factory DateFormatter.withLength(DataProvider provider, Locale locale, DateTimeLength length) { final result = _icu4x_DateFormatter_create_with_length_mv1(provider._ffi, locale._ffi, length.index); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw PatternLoadError.values.firstWhere((v) => v._ffi == result.union.err); } return DateFormatter._fromFfi(result.union.ok, []); } /// Formats a [`Date`] to a string. /// - /// Throws [Error] on failure. + /// Throws [DateTimeFormatError] on failure. String formatDate(Date value) { final write = _Write(); final result = _icu4x_DateFormatter_format_date_mv1(_ffi, value._ffi, write._ffi); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw DateTimeFormatError.values.firstWhere((v) => v._ffi == result.union.err); } return write.finalize(); } @@ -52,24 +52,24 @@ final class DateFormatter implements ffi.Finalizable { /// /// Will convert to this formatter's calendar first /// - /// Throws [Error] on failure. + /// Throws [DateTimeFormatError] on failure. String formatIsoDate(IsoDate value) { final write = _Write(); final result = _icu4x_DateFormatter_format_iso_date_mv1(_ffi, value._ffi, write._ffi); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw DateTimeFormatError.values.firstWhere((v) => v._ffi == result.union.err); } return write.finalize(); } /// Formats a [`DateTime`] to a string. /// - /// Throws [Error] on failure. + /// Throws [DateTimeFormatError] on failure. String formatDatetime(DateTime value) { final write = _Write(); final result = _icu4x_DateFormatter_format_datetime_mv1(_ffi, value._ffi, write._ffi); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw DateTimeFormatError.values.firstWhere((v) => v._ffi == result.union.err); } return write.finalize(); } @@ -78,12 +78,12 @@ final class DateFormatter implements ffi.Finalizable { /// /// Will convert to this formatter's calendar first /// - /// Throws [Error] on failure. + /// Throws [DateTimeFormatError] on failure. String formatIsoDatetime(IsoDateTime value) { final write = _Write(); final result = _icu4x_DateFormatter_format_iso_datetime_mv1(_ffi, value._ffi, write._ffi); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw DateTimeFormatError.values.firstWhere((v) => v._ffi == result.union.err); } return write.finalize(); } diff --git a/ffi/capi/bindings/dart/DateTimeFormatError.g.dart b/ffi/capi/bindings/dart/DateTimeFormatError.g.dart new file mode 100644 index 00000000000..6f16a1e5301 --- /dev/null +++ b/ffi/capi/bindings/dart/DateTimeFormatError.g.dart @@ -0,0 +1,47 @@ +// generated by diplomat-tool + +part of 'lib.g.dart'; + +/// Additional information: [1](https://docs.rs/icu/latest/icu/datetime/enum.DateTimeWriteError.html) +enum DateTimeFormatError { + unknown, + + missingInputField, + + zoneInfoMissingFields, + + invalidEra, + + invalidMonthCode, + + invalidCyclicYear, + + namesNotLoaded, + + fixedDecimalFormatterNotLoaded, + + unsupportedField; + + int get _ffi { + switch (this) { + case unknown: + return 0; + case missingInputField: + return 1; + case zoneInfoMissingFields: + return 2; + case invalidEra: + return 3; + case invalidMonthCode: + return 4; + case invalidCyclicYear: + return 5; + case namesNotLoaded: + return 16; + case fixedDecimalFormatterNotLoaded: + return 17; + case unsupportedField: + return 18; + } + } +} diff --git a/ffi/capi/bindings/dart/DateTimeFormatter.g.dart b/ffi/capi/bindings/dart/DateTimeFormatter.g.dart index c878f856594..eeca2e9b104 100644 --- a/ffi/capi/bindings/dart/DateTimeFormatter.g.dart +++ b/ffi/capi/bindings/dart/DateTimeFormatter.g.dart @@ -27,23 +27,23 @@ final class DateTimeFormatter implements ffi.Finalizable { /// Creates a new [`DateTimeFormatter`] from locale data. /// - /// Throws [Error] on failure. + /// Throws [PatternLoadError] on failure. factory DateTimeFormatter.withLength(DataProvider provider, Locale locale, DateTimeLength length) { final result = _icu4x_DateTimeFormatter_create_with_length_mv1(provider._ffi, locale._ffi, length.index); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw PatternLoadError.values.firstWhere((v) => v._ffi == result.union.err); } return DateTimeFormatter._fromFfi(result.union.ok, []); } /// Formats a [`DateTime`] to a string. /// - /// Throws [Error] on failure. + /// Throws [DateTimeFormatError] on failure. String formatDatetime(DateTime value) { final write = _Write(); final result = _icu4x_DateTimeFormatter_format_datetime_mv1(_ffi, value._ffi, write._ffi); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw DateTimeFormatError.values.firstWhere((v) => v._ffi == result.union.err); } return write.finalize(); } @@ -52,12 +52,12 @@ final class DateTimeFormatter implements ffi.Finalizable { /// /// Will convert to this formatter's calendar first /// - /// Throws [Error] on failure. + /// Throws [DateTimeFormatError] on failure. String formatIsoDatetime(IsoDateTime value) { final write = _Write(); final result = _icu4x_DateTimeFormatter_format_iso_datetime_mv1(_ffi, value._ffi, write._ffi); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw DateTimeFormatError.values.firstWhere((v) => v._ffi == result.union.err); } return write.finalize(); } diff --git a/ffi/capi/bindings/dart/Error.g.dart b/ffi/capi/bindings/dart/Error.g.dart deleted file mode 100644 index b0ef38a24db..00000000000 --- a/ffi/capi/bindings/dart/Error.g.dart +++ /dev/null @@ -1,107 +0,0 @@ -// generated by diplomat-tool - -part of 'lib.g.dart'; - -/// Legacy error -/// -/// Additional information: [1](https://docs.rs/icu/latest/icu/datetime/enum.DateTimeError.html), [2](https://docs.rs/icu/latest/icu/provider/struct.DataError.html), [3](https://docs.rs/icu/latest/icu/provider/enum.DataErrorKind.html) -enum Error { - /// The error is not currently categorized as Error. - /// Please file a bug - unknownError, - - dataMissingDataMarkerError, - - dataMissingLocaleError, - - dataNeedsLocaleError, - - dataExtraneousLocaleError, - - dataFilteredResourceError, - - dataMismatchedTypeError, - - dataCustomError, - - dataIoError, - - dataUnavailableBufferFormatError, - - dateTimePatternError, - - dateTimeMissingInputFieldError, - - dateTimeSkeletonError, - - dateTimeUnsupportedFieldError, - - dateTimeUnsupportedOptionsError, - - dateTimeMissingWeekdaySymbolError, - - dateTimeMissingMonthSymbolError, - - dateTimeFixedDecimalError, - - dateTimeMismatchedCalendarError, - - dateTimeDuplicateFieldError, - - dateTimeTooNarrowError, - - dateTimeMissingNamesError, - - dateTimeZoneInfoMissingFieldsError; - - int get _ffi { - switch (this) { - case unknownError: - return 0; - case dataMissingDataMarkerError: - return 256; - case dataMissingLocaleError: - return 258; - case dataNeedsLocaleError: - return 260; - case dataExtraneousLocaleError: - return 261; - case dataFilteredResourceError: - return 262; - case dataMismatchedTypeError: - return 263; - case dataCustomError: - return 266; - case dataIoError: - return 267; - case dataUnavailableBufferFormatError: - return 268; - case dateTimePatternError: - return 2048; - case dateTimeMissingInputFieldError: - return 2049; - case dateTimeSkeletonError: - return 2050; - case dateTimeUnsupportedFieldError: - return 2051; - case dateTimeUnsupportedOptionsError: - return 2052; - case dateTimeMissingWeekdaySymbolError: - return 2053; - case dateTimeMissingMonthSymbolError: - return 2054; - case dateTimeFixedDecimalError: - return 2055; - case dateTimeMismatchedCalendarError: - return 2056; - case dateTimeDuplicateFieldError: - return 2057; - case dateTimeTooNarrowError: - return 2058; - case dateTimeMissingNamesError: - return 2059; - case dateTimeZoneInfoMissingFieldsError: - return 2176; - } - } -} diff --git a/ffi/capi/bindings/dart/GregorianDateFormatter.g.dart b/ffi/capi/bindings/dart/GregorianDateFormatter.g.dart index ecc97417e35..473eecfb2d0 100644 --- a/ffi/capi/bindings/dart/GregorianDateFormatter.g.dart +++ b/ffi/capi/bindings/dart/GregorianDateFormatter.g.dart @@ -27,11 +27,11 @@ final class GregorianDateFormatter implements ffi.Finalizable { /// Creates a new [`GregorianDateFormatter`] from locale data. /// - /// Throws [Error] on failure. + /// Throws [PatternLoadError] on failure. factory GregorianDateFormatter.withLength(DataProvider provider, Locale locale, DateTimeLength length) { final result = _icu4x_GregorianDateFormatter_create_with_length_mv1(provider._ffi, locale._ffi, length.index); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw PatternLoadError.values.firstWhere((v) => v._ffi == result.union.err); } return GregorianDateFormatter._fromFfi(result.union.ok, []); } diff --git a/ffi/capi/bindings/dart/GregorianDateTimeFormatter.g.dart b/ffi/capi/bindings/dart/GregorianDateTimeFormatter.g.dart index c8bfdb17179..9883386a9ad 100644 --- a/ffi/capi/bindings/dart/GregorianDateTimeFormatter.g.dart +++ b/ffi/capi/bindings/dart/GregorianDateTimeFormatter.g.dart @@ -27,11 +27,11 @@ final class GregorianDateTimeFormatter implements ffi.Finalizable { /// Creates a new [`GregorianDateFormatter`] from locale data. /// - /// Throws [Error] on failure. + /// Throws [PatternLoadError] on failure. factory GregorianDateTimeFormatter.withLength(DataProvider provider, Locale locale, DateTimeLength length) { final result = _icu4x_GregorianDateTimeFormatter_create_with_length_mv1(provider._ffi, locale._ffi, length.index); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw PatternLoadError.values.firstWhere((v) => v._ffi == result.union.err); } return GregorianDateTimeFormatter._fromFfi(result.union.ok, []); } diff --git a/ffi/capi/bindings/dart/GregorianZonedDateTimeFormatter.g.dart b/ffi/capi/bindings/dart/GregorianZonedDateTimeFormatter.g.dart index 9530d975d73..22b5b69b01f 100644 --- a/ffi/capi/bindings/dart/GregorianZonedDateTimeFormatter.g.dart +++ b/ffi/capi/bindings/dart/GregorianZonedDateTimeFormatter.g.dart @@ -29,23 +29,23 @@ final class GregorianZonedDateTimeFormatter implements ffi.Finalizable { /// This function has `date_length` and `time_length` arguments and uses default options /// for the time zone. /// - /// Throws [Error] on failure. + /// Throws [PatternLoadError] on failure. factory GregorianZonedDateTimeFormatter.withLength(DataProvider provider, Locale locale, DateTimeLength length) { final result = _icu4x_GregorianZonedDateTimeFormatter_create_with_length_mv1(provider._ffi, locale._ffi, length.index); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw PatternLoadError.values.firstWhere((v) => v._ffi == result.union.err); } return GregorianZonedDateTimeFormatter._fromFfi(result.union.ok, []); } /// Formats a [`IsoDateTime`] and [`TimeZoneInfo`] to a string. /// - /// Throws [Error] on failure. + /// Throws [DateTimeFormatError] on failure. String formatIsoDatetimeWithCustomTimeZone(IsoDateTime datetime, TimeZoneInfo timeZone) { final write = _Write(); final result = _icu4x_GregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1(_ffi, datetime._ffi, timeZone._ffi, write._ffi); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw DateTimeFormatError.values.firstWhere((v) => v._ffi == result.union.err); } return write.finalize(); } diff --git a/ffi/capi/bindings/dart/LocaleCanonicalizer.g.dart b/ffi/capi/bindings/dart/LocaleCanonicalizer.g.dart index ff8c6754d3e..39eb18d0fe0 100644 --- a/ffi/capi/bindings/dart/LocaleCanonicalizer.g.dart +++ b/ffi/capi/bindings/dart/LocaleCanonicalizer.g.dart @@ -28,11 +28,11 @@ final class LocaleCanonicalizer implements ffi.Finalizable { /// /// See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/locale/struct.LocaleCanonicalizer.html#method.new) for more information. /// - /// Throws [Error] on failure. + /// Throws [DataError] on failure. factory LocaleCanonicalizer(DataProvider provider) { final result = _icu4x_LocaleCanonicalizer_create_mv1(provider._ffi); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw DataError.values[result.union.err]; } return LocaleCanonicalizer._fromFfi(result.union.ok, []); } @@ -41,11 +41,11 @@ final class LocaleCanonicalizer implements ffi.Finalizable { /// /// See the [Rust documentation for `new_with_expander`](https://docs.rs/icu/latest/icu/locale/struct.LocaleCanonicalizer.html#method.new_with_expander) for more information. /// - /// Throws [Error] on failure. + /// Throws [DataError] on failure. factory LocaleCanonicalizer.extended(DataProvider provider) { final result = _icu4x_LocaleCanonicalizer_create_extended_mv1(provider._ffi); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw DataError.values[result.union.err]; } return LocaleCanonicalizer._fromFfi(result.union.ok, []); } diff --git a/ffi/capi/bindings/dart/LocaleExpander.g.dart b/ffi/capi/bindings/dart/LocaleExpander.g.dart index f58c4d72306..ef7d416aa7b 100644 --- a/ffi/capi/bindings/dart/LocaleExpander.g.dart +++ b/ffi/capi/bindings/dart/LocaleExpander.g.dart @@ -28,11 +28,11 @@ final class LocaleExpander implements ffi.Finalizable { /// /// See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html#method.new) for more information. /// - /// Throws [Error] on failure. + /// Throws [DataError] on failure. factory LocaleExpander(DataProvider provider) { final result = _icu4x_LocaleExpander_create_mv1(provider._ffi); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw DataError.values[result.union.err]; } return LocaleExpander._fromFfi(result.union.ok, []); } @@ -41,11 +41,11 @@ final class LocaleExpander implements ffi.Finalizable { /// /// See the [Rust documentation for `new_extended`](https://docs.rs/icu/latest/icu/locale/struct.LocaleExpander.html#method.new_extended) for more information. /// - /// Throws [Error] on failure. + /// Throws [DataError] on failure. factory LocaleExpander.extended(DataProvider provider) { final result = _icu4x_LocaleExpander_create_extended_mv1(provider._ffi); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw DataError.values[result.union.err]; } return LocaleExpander._fromFfi(result.union.ok, []); } diff --git a/ffi/capi/bindings/dart/PatternLoadError.g.dart b/ffi/capi/bindings/dart/PatternLoadError.g.dart new file mode 100644 index 00000000000..4a236ae0a58 --- /dev/null +++ b/ffi/capi/bindings/dart/PatternLoadError.g.dart @@ -0,0 +1,59 @@ +// generated by diplomat-tool + +part of 'lib.g.dart'; + +/// Additional information: [1](https://docs.rs/icu/latest/icu/datetime/enum.PatternLoadError.html), [2](https://docs.rs/icu/latest/icu/provider/struct.DataError.html), [3](https://docs.rs/icu/latest/icu/provider/enum.DataErrorKind.html) +enum PatternLoadError { + unknown, + + unsupportedField, + + duplicateField, + + typeTooSpecific, + + dataMarkerNotFound, + + dataIdentifierNotFound, + + dataInvalidRequest, + + dataInconsistentData, + + dataDowncast, + + dataDeserialize, + + dataCustom, + + dataIo; + + int get _ffi { + switch (this) { + case unknown: + return 0; + case unsupportedField: + return 2051; + case duplicateField: + return 2057; + case typeTooSpecific: + return 2058; + case dataMarkerNotFound: + return 1; + case dataIdentifierNotFound: + return 2; + case dataInvalidRequest: + return 3; + case dataInconsistentData: + return 4; + case dataDowncast: + return 5; + case dataDeserialize: + return 6; + case dataCustom: + return 7; + case dataIo: + return 8; + } + } +} diff --git a/ffi/capi/bindings/dart/TimeFormatter.g.dart b/ffi/capi/bindings/dart/TimeFormatter.g.dart index 5fecc0473be..7503f6aa5be 100644 --- a/ffi/capi/bindings/dart/TimeFormatter.g.dart +++ b/ffi/capi/bindings/dart/TimeFormatter.g.dart @@ -26,11 +26,11 @@ final class TimeFormatter implements ffi.Finalizable { /// Creates a new [`TimeFormatter`] from locale data. /// - /// Throws [Error] on failure. + /// Throws [PatternLoadError] on failure. factory TimeFormatter.withLength(DataProvider provider, Locale locale, DateTimeLength length) { final result = _icu4x_TimeFormatter_create_with_length_mv1(provider._ffi, locale._ffi, length.index); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw PatternLoadError.values.firstWhere((v) => v._ffi == result.union.err); } return TimeFormatter._fromFfi(result.union.ok, []); } diff --git a/ffi/capi/bindings/dart/ZonedDateTimeFormatter.g.dart b/ffi/capi/bindings/dart/ZonedDateTimeFormatter.g.dart index 48204f3d140..90bd04c982a 100644 --- a/ffi/capi/bindings/dart/ZonedDateTimeFormatter.g.dart +++ b/ffi/capi/bindings/dart/ZonedDateTimeFormatter.g.dart @@ -29,35 +29,35 @@ final class ZonedDateTimeFormatter implements ffi.Finalizable { /// This function has `date_length` and `time_length` arguments and uses default options /// for the time zone. /// - /// Throws [Error] on failure. + /// Throws [PatternLoadError] on failure. factory ZonedDateTimeFormatter.withLength(DataProvider provider, Locale locale, DateTimeLength length) { final result = _icu4x_ZonedDateTimeFormatter_create_with_length_mv1(provider._ffi, locale._ffi, length.index); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw PatternLoadError.values.firstWhere((v) => v._ffi == result.union.err); } return ZonedDateTimeFormatter._fromFfi(result.union.ok, []); } /// Formats a [`DateTime`] and [`TimeZoneInfo`] to a string. /// - /// Throws [Error] on failure. + /// Throws [DateTimeFormatError] on failure. String formatDatetimeWithCustomTimeZone(DateTime datetime, TimeZoneInfo timeZone) { final write = _Write(); final result = _icu4x_ZonedDateTimeFormatter_format_datetime_with_custom_time_zone_mv1(_ffi, datetime._ffi, timeZone._ffi, write._ffi); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw DateTimeFormatError.values.firstWhere((v) => v._ffi == result.union.err); } return write.finalize(); } /// Formats a [`IsoDateTime`] and [`TimeZoneInfo`] to a string. /// - /// Throws [Error] on failure. + /// Throws [DateTimeFormatError] on failure. String formatIsoDatetimeWithCustomTimeZone(IsoDateTime datetime, TimeZoneInfo timeZone) { final write = _Write(); final result = _icu4x_ZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone_mv1(_ffi, datetime._ffi, timeZone._ffi, write._ffi); if (!result.isOk) { - throw Error.values.firstWhere((v) => v._ffi == result.union.err); + throw DateTimeFormatError.values.firstWhere((v) => v._ffi == result.union.err); } return write.finalize(); } diff --git a/ffi/capi/bindings/dart/lib.g.dart b/ffi/capi/bindings/dart/lib.g.dart index 4329913216b..f5d5957857a 100644 --- a/ffi/capi/bindings/dart/lib.g.dart +++ b/ffi/capi/bindings/dart/lib.g.dart @@ -45,6 +45,7 @@ part 'DataProvider.g.dart'; part 'Date.g.dart'; part 'DateFormatter.g.dart'; part 'DateTime.g.dart'; +part 'DateTimeFormatError.g.dart'; part 'DateTimeFormatter.g.dart'; part 'DateTimeLength.g.dart'; part 'Decomposed.g.dart'; @@ -53,7 +54,6 @@ part 'DisplayNamesFallback.g.dart'; part 'DisplayNamesOptions.g.dart'; part 'DisplayNamesStyle.g.dart'; part 'EmojiSetData.g.dart'; -part 'Error.g.dart'; part 'ExemplarCharacters.g.dart'; part 'FixedDecimal.g.dart'; part 'FixedDecimalFormatter.g.dart'; @@ -101,6 +101,7 @@ part 'LocaleParseError.g.dart'; part 'Logger.g.dart'; part 'MeasureUnit.g.dart'; part 'MeasureUnitParser.g.dart'; +part 'PatternLoadError.g.dart'; part 'PluralCategories.g.dart'; part 'PluralCategory.g.dart'; part 'PluralOperands.g.dart'; diff --git a/ffi/capi/bindings/js/DateFormatter.d.ts b/ffi/capi/bindings/js/DateFormatter.d.ts index 953f6718649..b21807c42ff 100644 --- a/ffi/capi/bindings/js/DateFormatter.d.ts +++ b/ffi/capi/bindings/js/DateFormatter.d.ts @@ -2,11 +2,12 @@ import type { DataProvider } from "./DataProvider" import type { Date } from "./Date" import type { DateTime } from "./DateTime" +import type { DateTimeFormatError } from "./DateTimeFormatError" import type { DateTimeLength } from "./DateTimeLength" -import type { Error } from "./Error" import type { IsoDate } from "./IsoDate" import type { IsoDateTime } from "./IsoDateTime" import type { Locale } from "./Locale" +import type { PatternLoadError } from "./PatternLoadError" import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; diff --git a/ffi/capi/bindings/js/DateFormatter.mjs b/ffi/capi/bindings/js/DateFormatter.mjs index a41b32329a0..113fffcfc30 100644 --- a/ffi/capi/bindings/js/DateFormatter.mjs +++ b/ffi/capi/bindings/js/DateFormatter.mjs @@ -2,11 +2,12 @@ import { DataProvider } from "./DataProvider.mjs" import { Date } from "./Date.mjs" import { DateTime } from "./DateTime.mjs" +import { DateTimeFormatError } from "./DateTimeFormatError.mjs" import { DateTimeLength } from "./DateTimeLength.mjs" -import { Error } from "./Error.mjs" import { IsoDate } from "./IsoDate.mjs" import { IsoDateTime } from "./IsoDateTime.mjs" import { Locale } from "./Locale.mjs" +import { PatternLoadError } from "./PatternLoadError.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; @@ -54,8 +55,8 @@ export class DateFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('PatternLoadError: ' + cause.value, { cause }); } return new DateFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } @@ -74,8 +75,8 @@ export class DateFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('DateTimeFormatError: ' + cause.value, { cause }); } return write.readString8(); } @@ -96,8 +97,8 @@ export class DateFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('DateTimeFormatError: ' + cause.value, { cause }); } return write.readString8(); } @@ -118,8 +119,8 @@ export class DateFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('DateTimeFormatError: ' + cause.value, { cause }); } return write.readString8(); } @@ -140,8 +141,8 @@ export class DateFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('DateTimeFormatError: ' + cause.value, { cause }); } return write.readString8(); } diff --git a/ffi/capi/bindings/js/DateTimeFormatError.d.ts b/ffi/capi/bindings/js/DateTimeFormatError.d.ts new file mode 100644 index 00000000000..3be4533d45d --- /dev/null +++ b/ffi/capi/bindings/js/DateTimeFormatError.d.ts @@ -0,0 +1,23 @@ +// generated by diplomat-tool +import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** Additional information: [1](https://docs.rs/icu/latest/icu/datetime/enum.DateTimeWriteError.html) +*/ +export class DateTimeFormatError { + constructor(value : DateTimeFormatError | string); + + get value() : string; + + get ffiValue() : number; + + static Unknown : DateTimeFormatError; + static MissingInputField : DateTimeFormatError; + static ZoneInfoMissingFields : DateTimeFormatError; + static InvalidEra : DateTimeFormatError; + static InvalidMonthCode : DateTimeFormatError; + static InvalidCyclicYear : DateTimeFormatError; + static NamesNotLoaded : DateTimeFormatError; + static FixedDecimalFormatterNotLoaded : DateTimeFormatError; + static UnsupportedField : DateTimeFormatError; +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DateTimeFormatError.mjs b/ffi/capi/bindings/js/DateTimeFormatError.mjs new file mode 100644 index 00000000000..9ceadbfbc92 --- /dev/null +++ b/ffi/capi/bindings/js/DateTimeFormatError.mjs @@ -0,0 +1,84 @@ +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** Additional information: [1](https://docs.rs/icu/latest/icu/datetime/enum.DateTimeWriteError.html) +*/ +export class DateTimeFormatError { + #value = undefined; + + static #values = new Map([ + ["Unknown", 0], + ["MissingInputField", 1], + ["ZoneInfoMissingFields", 2], + ["InvalidEra", 3], + ["InvalidMonthCode", 4], + ["InvalidCyclicYear", 5], + ["NamesNotLoaded", 16], + ["FixedDecimalFormatterNotLoaded", 17], + ["UnsupportedField", 18] + ]); + + static getAllEntries() { + return DateTimeFormatError.#values.entries(); + } + + constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return DateTimeFormatError.#objectValues[arguments[1]]; + } + + if (value instanceof DateTimeFormatError) { + return value; + } + + let intVal = DateTimeFormatError.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return DateTimeFormatError.#objectValues[intVal]; + } + + throw TypeError(value + " is not a DateTimeFormatError and does not correspond to any of its enumerator values."); + } + + get value() { + for (let entry of DateTimeFormatError.#values) { + if (entry[1] == this.#value) { + return entry[0]; + } + } + } + + get ffiValue() { + return this.#value; + } + static #objectValues = { + [0]: new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + [1]: new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + [2]: new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + [3]: new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + [4]: new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), + [5]: new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5), + [16]: new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 16), + [17]: new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 17), + [18]: new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 18), + }; + + static Unknown = DateTimeFormatError.#objectValues[0]; + static MissingInputField = DateTimeFormatError.#objectValues[1]; + static ZoneInfoMissingFields = DateTimeFormatError.#objectValues[2]; + static InvalidEra = DateTimeFormatError.#objectValues[3]; + static InvalidMonthCode = DateTimeFormatError.#objectValues[4]; + static InvalidCyclicYear = DateTimeFormatError.#objectValues[5]; + static NamesNotLoaded = DateTimeFormatError.#objectValues[16]; + static FixedDecimalFormatterNotLoaded = DateTimeFormatError.#objectValues[17]; + static UnsupportedField = DateTimeFormatError.#objectValues[18]; +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/DateTimeFormatter.d.ts b/ffi/capi/bindings/js/DateTimeFormatter.d.ts index f8a085bfb26..0752396a7f5 100644 --- a/ffi/capi/bindings/js/DateTimeFormatter.d.ts +++ b/ffi/capi/bindings/js/DateTimeFormatter.d.ts @@ -1,10 +1,11 @@ // generated by diplomat-tool import type { DataProvider } from "./DataProvider" import type { DateTime } from "./DateTime" +import type { DateTimeFormatError } from "./DateTimeFormatError" import type { DateTimeLength } from "./DateTimeLength" -import type { Error } from "./Error" import type { IsoDateTime } from "./IsoDateTime" import type { Locale } from "./Locale" +import type { PatternLoadError } from "./PatternLoadError" import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; diff --git a/ffi/capi/bindings/js/DateTimeFormatter.mjs b/ffi/capi/bindings/js/DateTimeFormatter.mjs index 714b4d03ffb..18aa8505b3d 100644 --- a/ffi/capi/bindings/js/DateTimeFormatter.mjs +++ b/ffi/capi/bindings/js/DateTimeFormatter.mjs @@ -1,10 +1,11 @@ // generated by diplomat-tool import { DataProvider } from "./DataProvider.mjs" import { DateTime } from "./DateTime.mjs" +import { DateTimeFormatError } from "./DateTimeFormatError.mjs" import { DateTimeLength } from "./DateTimeLength.mjs" -import { Error } from "./Error.mjs" import { IsoDateTime } from "./IsoDateTime.mjs" import { Locale } from "./Locale.mjs" +import { PatternLoadError } from "./PatternLoadError.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; @@ -52,8 +53,8 @@ export class DateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('PatternLoadError: ' + cause.value, { cause }); } return new DateTimeFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } @@ -72,8 +73,8 @@ export class DateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('DateTimeFormatError: ' + cause.value, { cause }); } return write.readString8(); } @@ -94,8 +95,8 @@ export class DateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('DateTimeFormatError: ' + cause.value, { cause }); } return write.readString8(); } diff --git a/ffi/capi/bindings/js/Error.d.ts b/ffi/capi/bindings/js/Error.d.ts deleted file mode 100644 index ce72e2d4996..00000000000 --- a/ffi/capi/bindings/js/Error.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -// generated by diplomat-tool -import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; - -// Base enumerator definition -/** Legacy error -* -*Additional information: [1](https://docs.rs/icu/latest/icu/datetime/enum.DateTimeError.html), [2](https://docs.rs/icu/latest/icu/provider/struct.DataError.html), [3](https://docs.rs/icu/latest/icu/provider/enum.DataErrorKind.html) -*/ -export class Error { - constructor(value : Error | string); - - get value() : string; - - get ffiValue() : number; - - static UnknownError : Error; - static DataMissingDataMarkerError : Error; - static DataMissingLocaleError : Error; - static DataNeedsLocaleError : Error; - static DataExtraneousLocaleError : Error; - static DataFilteredResourceError : Error; - static DataMismatchedTypeError : Error; - static DataCustomError : Error; - static DataIoError : Error; - static DataUnavailableBufferFormatError : Error; - static DateTimePatternError : Error; - static DateTimeMissingInputFieldError : Error; - static DateTimeSkeletonError : Error; - static DateTimeUnsupportedFieldError : Error; - static DateTimeUnsupportedOptionsError : Error; - static DateTimeMissingWeekdaySymbolError : Error; - static DateTimeMissingMonthSymbolError : Error; - static DateTimeFixedDecimalError : Error; - static DateTimeMismatchedCalendarError : Error; - static DateTimeDuplicateFieldError : Error; - static DateTimeTooNarrowError : Error; - static DateTimeMissingNamesError : Error; - static DateTimeZoneInfoMissingFieldsError : Error; -} \ No newline at end of file diff --git a/ffi/capi/bindings/js/Error.mjs b/ffi/capi/bindings/js/Error.mjs deleted file mode 100644 index b0d724f758b..00000000000 --- a/ffi/capi/bindings/js/Error.mjs +++ /dev/null @@ -1,128 +0,0 @@ -// generated by diplomat-tool -import wasm from "./diplomat-wasm.mjs"; -import * as diplomatRuntime from "./diplomat-runtime.mjs"; - -// Base enumerator definition -/** Legacy error -* -*Additional information: [1](https://docs.rs/icu/latest/icu/datetime/enum.DateTimeError.html), [2](https://docs.rs/icu/latest/icu/provider/struct.DataError.html), [3](https://docs.rs/icu/latest/icu/provider/enum.DataErrorKind.html) -*/ -export class Error { - #value = undefined; - - static #values = new Map([ - ["UnknownError", 0], - ["DataMissingDataMarkerError", 256], - ["DataMissingLocaleError", 258], - ["DataNeedsLocaleError", 260], - ["DataExtraneousLocaleError", 261], - ["DataFilteredResourceError", 262], - ["DataMismatchedTypeError", 263], - ["DataCustomError", 266], - ["DataIoError", 267], - ["DataUnavailableBufferFormatError", 268], - ["DateTimePatternError", 2048], - ["DateTimeMissingInputFieldError", 2049], - ["DateTimeSkeletonError", 2050], - ["DateTimeUnsupportedFieldError", 2051], - ["DateTimeUnsupportedOptionsError", 2052], - ["DateTimeMissingWeekdaySymbolError", 2053], - ["DateTimeMissingMonthSymbolError", 2054], - ["DateTimeFixedDecimalError", 2055], - ["DateTimeMismatchedCalendarError", 2056], - ["DateTimeDuplicateFieldError", 2057], - ["DateTimeTooNarrowError", 2058], - ["DateTimeMissingNamesError", 2059], - ["DateTimeZoneInfoMissingFieldsError", 2176] - ]); - - static getAllEntries() { - return Error.#values.entries(); - } - - constructor(value) { - if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { - // We pass in two internalConstructor arguments to create *new* - // instances of this type, otherwise the enums are treated as singletons. - if (arguments[1] === diplomatRuntime.internalConstructor ) { - this.#value = arguments[2]; - return; - } - return Error.#objectValues[arguments[1]]; - } - - if (value instanceof Error) { - return value; - } - - let intVal = Error.#values.get(value); - - // Nullish check, checks for null or undefined - if (intVal == null) { - return Error.#objectValues[intVal]; - } - - throw TypeError(value + " is not a Error and does not correspond to any of its enumerator values."); - } - - get value() { - for (let entry of Error.#values) { - if (entry[1] == this.#value) { - return entry[0]; - } - } - } - - get ffiValue() { - return this.#value; - } - static #objectValues = { - [0]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), - [256]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 256), - [258]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 258), - [260]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 260), - [261]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 261), - [262]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 262), - [263]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 263), - [266]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 266), - [267]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 267), - [268]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 268), - [2048]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2048), - [2049]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2049), - [2050]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2050), - [2051]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2051), - [2052]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2052), - [2053]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2053), - [2054]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2054), - [2055]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2055), - [2056]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2056), - [2057]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2057), - [2058]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2058), - [2059]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2059), - [2176]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2176), - }; - - static UnknownError = Error.#objectValues[0]; - static DataMissingDataMarkerError = Error.#objectValues[256]; - static DataMissingLocaleError = Error.#objectValues[258]; - static DataNeedsLocaleError = Error.#objectValues[260]; - static DataExtraneousLocaleError = Error.#objectValues[261]; - static DataFilteredResourceError = Error.#objectValues[262]; - static DataMismatchedTypeError = Error.#objectValues[263]; - static DataCustomError = Error.#objectValues[266]; - static DataIoError = Error.#objectValues[267]; - static DataUnavailableBufferFormatError = Error.#objectValues[268]; - static DateTimePatternError = Error.#objectValues[2048]; - static DateTimeMissingInputFieldError = Error.#objectValues[2049]; - static DateTimeSkeletonError = Error.#objectValues[2050]; - static DateTimeUnsupportedFieldError = Error.#objectValues[2051]; - static DateTimeUnsupportedOptionsError = Error.#objectValues[2052]; - static DateTimeMissingWeekdaySymbolError = Error.#objectValues[2053]; - static DateTimeMissingMonthSymbolError = Error.#objectValues[2054]; - static DateTimeFixedDecimalError = Error.#objectValues[2055]; - static DateTimeMismatchedCalendarError = Error.#objectValues[2056]; - static DateTimeDuplicateFieldError = Error.#objectValues[2057]; - static DateTimeTooNarrowError = Error.#objectValues[2058]; - static DateTimeMissingNamesError = Error.#objectValues[2059]; - static DateTimeZoneInfoMissingFieldsError = Error.#objectValues[2176]; -} \ No newline at end of file diff --git a/ffi/capi/bindings/js/GregorianDateFormatter.d.ts b/ffi/capi/bindings/js/GregorianDateFormatter.d.ts index 60ed82351de..a52e0b0ee4d 100644 --- a/ffi/capi/bindings/js/GregorianDateFormatter.d.ts +++ b/ffi/capi/bindings/js/GregorianDateFormatter.d.ts @@ -1,10 +1,10 @@ // generated by diplomat-tool import type { DataProvider } from "./DataProvider" import type { DateTimeLength } from "./DateTimeLength" -import type { Error } from "./Error" import type { IsoDate } from "./IsoDate" import type { IsoDateTime } from "./IsoDateTime" import type { Locale } from "./Locale" +import type { PatternLoadError } from "./PatternLoadError" import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; diff --git a/ffi/capi/bindings/js/GregorianDateFormatter.mjs b/ffi/capi/bindings/js/GregorianDateFormatter.mjs index 53fef2ab351..50117e88b18 100644 --- a/ffi/capi/bindings/js/GregorianDateFormatter.mjs +++ b/ffi/capi/bindings/js/GregorianDateFormatter.mjs @@ -1,10 +1,10 @@ // generated by diplomat-tool import { DataProvider } from "./DataProvider.mjs" import { DateTimeLength } from "./DateTimeLength.mjs" -import { Error } from "./Error.mjs" import { IsoDate } from "./IsoDate.mjs" import { IsoDateTime } from "./IsoDateTime.mjs" import { Locale } from "./Locale.mjs" +import { PatternLoadError } from "./PatternLoadError.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; @@ -52,8 +52,8 @@ export class GregorianDateFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('PatternLoadError: ' + cause.value, { cause }); } return new GregorianDateFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } diff --git a/ffi/capi/bindings/js/GregorianDateTimeFormatter.d.ts b/ffi/capi/bindings/js/GregorianDateTimeFormatter.d.ts index 48913124f8e..a3f88ea74a4 100644 --- a/ffi/capi/bindings/js/GregorianDateTimeFormatter.d.ts +++ b/ffi/capi/bindings/js/GregorianDateTimeFormatter.d.ts @@ -1,9 +1,9 @@ // generated by diplomat-tool import type { DataProvider } from "./DataProvider" import type { DateTimeLength } from "./DateTimeLength" -import type { Error } from "./Error" import type { IsoDateTime } from "./IsoDateTime" import type { Locale } from "./Locale" +import type { PatternLoadError } from "./PatternLoadError" import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; diff --git a/ffi/capi/bindings/js/GregorianDateTimeFormatter.mjs b/ffi/capi/bindings/js/GregorianDateTimeFormatter.mjs index 18cdc2d119f..1a1c0b0fe7c 100644 --- a/ffi/capi/bindings/js/GregorianDateTimeFormatter.mjs +++ b/ffi/capi/bindings/js/GregorianDateTimeFormatter.mjs @@ -1,9 +1,9 @@ // generated by diplomat-tool import { DataProvider } from "./DataProvider.mjs" import { DateTimeLength } from "./DateTimeLength.mjs" -import { Error } from "./Error.mjs" import { IsoDateTime } from "./IsoDateTime.mjs" import { Locale } from "./Locale.mjs" +import { PatternLoadError } from "./PatternLoadError.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; @@ -51,8 +51,8 @@ export class GregorianDateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('PatternLoadError: ' + cause.value, { cause }); } return new GregorianDateTimeFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } diff --git a/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.d.ts b/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.d.ts index aef979778be..ca0cdc2da2b 100644 --- a/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.d.ts +++ b/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.d.ts @@ -1,9 +1,10 @@ // generated by diplomat-tool import type { DataProvider } from "./DataProvider" +import type { DateTimeFormatError } from "./DateTimeFormatError" import type { DateTimeLength } from "./DateTimeLength" -import type { Error } from "./Error" import type { IsoDateTime } from "./IsoDateTime" import type { Locale } from "./Locale" +import type { PatternLoadError } from "./PatternLoadError" import type { TimeZoneInfo } from "./TimeZoneInfo" import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; diff --git a/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.mjs b/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.mjs index 4fa8ca9052c..5d9e2cd2535 100644 --- a/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.mjs +++ b/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.mjs @@ -1,9 +1,10 @@ // generated by diplomat-tool import { DataProvider } from "./DataProvider.mjs" +import { DateTimeFormatError } from "./DateTimeFormatError.mjs" import { DateTimeLength } from "./DateTimeLength.mjs" -import { Error } from "./Error.mjs" import { IsoDateTime } from "./IsoDateTime.mjs" import { Locale } from "./Locale.mjs" +import { PatternLoadError } from "./PatternLoadError.mjs" import { TimeZoneInfo } from "./TimeZoneInfo.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; @@ -51,8 +52,8 @@ export class GregorianZonedDateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('PatternLoadError: ' + cause.value, { cause }); } return new GregorianZonedDateTimeFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } @@ -71,8 +72,8 @@ export class GregorianZonedDateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('DateTimeFormatError: ' + cause.value, { cause }); } return write.readString8(); } diff --git a/ffi/capi/bindings/js/LocaleCanonicalizer.d.ts b/ffi/capi/bindings/js/LocaleCanonicalizer.d.ts index d95dfcee3c6..815227b7ff2 100644 --- a/ffi/capi/bindings/js/LocaleCanonicalizer.d.ts +++ b/ffi/capi/bindings/js/LocaleCanonicalizer.d.ts @@ -1,6 +1,6 @@ // generated by diplomat-tool +import type { DataError } from "./DataError" import type { DataProvider } from "./DataProvider" -import type { Error } from "./Error" import type { Locale } from "./Locale" import type { TransformResult } from "./TransformResult" import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; diff --git a/ffi/capi/bindings/js/LocaleCanonicalizer.mjs b/ffi/capi/bindings/js/LocaleCanonicalizer.mjs index 180c154483b..523b64126f3 100644 --- a/ffi/capi/bindings/js/LocaleCanonicalizer.mjs +++ b/ffi/capi/bindings/js/LocaleCanonicalizer.mjs @@ -1,6 +1,6 @@ // generated by diplomat-tool +import { DataError } from "./DataError.mjs" import { DataProvider } from "./DataProvider.mjs" -import { Error } from "./Error.mjs" import { Locale } from "./Locale.mjs" import { TransformResult } from "./TransformResult.mjs" import wasm from "./diplomat-wasm.mjs"; @@ -49,8 +49,8 @@ export class LocaleCanonicalizer { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new LocaleCanonicalizer(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } @@ -67,8 +67,8 @@ export class LocaleCanonicalizer { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new LocaleCanonicalizer(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } diff --git a/ffi/capi/bindings/js/LocaleExpander.d.ts b/ffi/capi/bindings/js/LocaleExpander.d.ts index 4c623e3a673..7f2c729cf55 100644 --- a/ffi/capi/bindings/js/LocaleExpander.d.ts +++ b/ffi/capi/bindings/js/LocaleExpander.d.ts @@ -1,6 +1,6 @@ // generated by diplomat-tool +import type { DataError } from "./DataError" import type { DataProvider } from "./DataProvider" -import type { Error } from "./Error" import type { Locale } from "./Locale" import type { TransformResult } from "./TransformResult" import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; diff --git a/ffi/capi/bindings/js/LocaleExpander.mjs b/ffi/capi/bindings/js/LocaleExpander.mjs index b640fd2b791..b8a257a6753 100644 --- a/ffi/capi/bindings/js/LocaleExpander.mjs +++ b/ffi/capi/bindings/js/LocaleExpander.mjs @@ -1,6 +1,6 @@ // generated by diplomat-tool +import { DataError } from "./DataError.mjs" import { DataProvider } from "./DataProvider.mjs" -import { Error } from "./Error.mjs" import { Locale } from "./Locale.mjs" import { TransformResult } from "./TransformResult.mjs" import wasm from "./diplomat-wasm.mjs"; @@ -49,8 +49,8 @@ export class LocaleExpander { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new LocaleExpander(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } @@ -67,8 +67,8 @@ export class LocaleExpander { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new LocaleExpander(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } diff --git a/ffi/capi/bindings/js/PatternLoadError.d.ts b/ffi/capi/bindings/js/PatternLoadError.d.ts new file mode 100644 index 00000000000..d1aa663a36e --- /dev/null +++ b/ffi/capi/bindings/js/PatternLoadError.d.ts @@ -0,0 +1,26 @@ +// generated by diplomat-tool +import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; + +// Base enumerator definition +/** Additional information: [1](https://docs.rs/icu/latest/icu/datetime/enum.PatternLoadError.html), [2](https://docs.rs/icu/latest/icu/provider/struct.DataError.html), [3](https://docs.rs/icu/latest/icu/provider/enum.DataErrorKind.html) +*/ +export class PatternLoadError { + constructor(value : PatternLoadError | string); + + get value() : string; + + get ffiValue() : number; + + static Unknown : PatternLoadError; + static UnsupportedField : PatternLoadError; + static DuplicateField : PatternLoadError; + static TypeTooSpecific : PatternLoadError; + static DataMarkerNotFound : PatternLoadError; + static DataIdentifierNotFound : PatternLoadError; + static DataInvalidRequest : PatternLoadError; + static DataInconsistentData : PatternLoadError; + static DataDowncast : PatternLoadError; + static DataDeserialize : PatternLoadError; + static DataCustom : PatternLoadError; + static DataIo : PatternLoadError; +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/PatternLoadError.mjs b/ffi/capi/bindings/js/PatternLoadError.mjs new file mode 100644 index 00000000000..a179787268e --- /dev/null +++ b/ffi/capi/bindings/js/PatternLoadError.mjs @@ -0,0 +1,93 @@ +// generated by diplomat-tool +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + +// Base enumerator definition +/** Additional information: [1](https://docs.rs/icu/latest/icu/datetime/enum.PatternLoadError.html), [2](https://docs.rs/icu/latest/icu/provider/struct.DataError.html), [3](https://docs.rs/icu/latest/icu/provider/enum.DataErrorKind.html) +*/ +export class PatternLoadError { + #value = undefined; + + static #values = new Map([ + ["Unknown", 0], + ["UnsupportedField", 2051], + ["DuplicateField", 2057], + ["TypeTooSpecific", 2058], + ["DataMarkerNotFound", 1], + ["DataIdentifierNotFound", 2], + ["DataInvalidRequest", 3], + ["DataInconsistentData", 4], + ["DataDowncast", 5], + ["DataDeserialize", 6], + ["DataCustom", 7], + ["DataIo", 8] + ]); + + static getAllEntries() { + return PatternLoadError.#values.entries(); + } + + constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return PatternLoadError.#objectValues[arguments[1]]; + } + + if (value instanceof PatternLoadError) { + return value; + } + + let intVal = PatternLoadError.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return PatternLoadError.#objectValues[intVal]; + } + + throw TypeError(value + " is not a PatternLoadError and does not correspond to any of its enumerator values."); + } + + get value() { + for (let entry of PatternLoadError.#values) { + if (entry[1] == this.#value) { + return entry[0]; + } + } + } + + get ffiValue() { + return this.#value; + } + static #objectValues = { + [0]: new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + [2051]: new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2051), + [2057]: new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2057), + [2058]: new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2058), + [1]: new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + [2]: new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + [3]: new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + [4]: new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), + [5]: new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5), + [6]: new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6), + [7]: new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7), + [8]: new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8), + }; + + static Unknown = PatternLoadError.#objectValues[0]; + static UnsupportedField = PatternLoadError.#objectValues[2051]; + static DuplicateField = PatternLoadError.#objectValues[2057]; + static TypeTooSpecific = PatternLoadError.#objectValues[2058]; + static DataMarkerNotFound = PatternLoadError.#objectValues[1]; + static DataIdentifierNotFound = PatternLoadError.#objectValues[2]; + static DataInvalidRequest = PatternLoadError.#objectValues[3]; + static DataInconsistentData = PatternLoadError.#objectValues[4]; + static DataDowncast = PatternLoadError.#objectValues[5]; + static DataDeserialize = PatternLoadError.#objectValues[6]; + static DataCustom = PatternLoadError.#objectValues[7]; + static DataIo = PatternLoadError.#objectValues[8]; +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeFormatter.d.ts b/ffi/capi/bindings/js/TimeFormatter.d.ts index f43e8059add..5b22cb9ca61 100644 --- a/ffi/capi/bindings/js/TimeFormatter.d.ts +++ b/ffi/capi/bindings/js/TimeFormatter.d.ts @@ -2,9 +2,9 @@ import type { DataProvider } from "./DataProvider" import type { DateTime } from "./DateTime" import type { DateTimeLength } from "./DateTimeLength" -import type { Error } from "./Error" import type { IsoDateTime } from "./IsoDateTime" import type { Locale } from "./Locale" +import type { PatternLoadError } from "./PatternLoadError" import type { Time } from "./Time" import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; diff --git a/ffi/capi/bindings/js/TimeFormatter.mjs b/ffi/capi/bindings/js/TimeFormatter.mjs index ec10b326dc8..b373bf2bfc7 100644 --- a/ffi/capi/bindings/js/TimeFormatter.mjs +++ b/ffi/capi/bindings/js/TimeFormatter.mjs @@ -2,9 +2,9 @@ import { DataProvider } from "./DataProvider.mjs" import { DateTime } from "./DateTime.mjs" import { DateTimeLength } from "./DateTimeLength.mjs" -import { Error } from "./Error.mjs" import { IsoDateTime } from "./IsoDateTime.mjs" import { Locale } from "./Locale.mjs" +import { PatternLoadError } from "./PatternLoadError.mjs" import { Time } from "./Time.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; @@ -52,8 +52,8 @@ export class TimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('PatternLoadError: ' + cause.value, { cause }); } return new TimeFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } diff --git a/ffi/capi/bindings/js/ZonedDateTimeFormatter.d.ts b/ffi/capi/bindings/js/ZonedDateTimeFormatter.d.ts index e78c2de4265..c7870a8ec7f 100644 --- a/ffi/capi/bindings/js/ZonedDateTimeFormatter.d.ts +++ b/ffi/capi/bindings/js/ZonedDateTimeFormatter.d.ts @@ -1,10 +1,11 @@ // generated by diplomat-tool import type { DataProvider } from "./DataProvider" import type { DateTime } from "./DateTime" +import type { DateTimeFormatError } from "./DateTimeFormatError" import type { DateTimeLength } from "./DateTimeLength" -import type { Error } from "./Error" import type { IsoDateTime } from "./IsoDateTime" import type { Locale } from "./Locale" +import type { PatternLoadError } from "./PatternLoadError" import type { TimeZoneInfo } from "./TimeZoneInfo" import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; diff --git a/ffi/capi/bindings/js/ZonedDateTimeFormatter.mjs b/ffi/capi/bindings/js/ZonedDateTimeFormatter.mjs index c142bb11b83..9048a60da53 100644 --- a/ffi/capi/bindings/js/ZonedDateTimeFormatter.mjs +++ b/ffi/capi/bindings/js/ZonedDateTimeFormatter.mjs @@ -1,10 +1,11 @@ // generated by diplomat-tool import { DataProvider } from "./DataProvider.mjs" import { DateTime } from "./DateTime.mjs" +import { DateTimeFormatError } from "./DateTimeFormatError.mjs" import { DateTimeLength } from "./DateTimeLength.mjs" -import { Error } from "./Error.mjs" import { IsoDateTime } from "./IsoDateTime.mjs" import { Locale } from "./Locale.mjs" +import { PatternLoadError } from "./PatternLoadError.mjs" import { TimeZoneInfo } from "./TimeZoneInfo.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; @@ -52,8 +53,8 @@ export class ZonedDateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new PatternLoadError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('PatternLoadError: ' + cause.value, { cause }); } return new ZonedDateTimeFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); } @@ -72,8 +73,8 @@ export class ZonedDateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('DateTimeFormatError: ' + cause.value, { cause }); } return write.readString8(); } @@ -94,8 +95,8 @@ export class ZonedDateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); - throw new globalThis.Error('Error: ' + cause.value, { cause }); + const cause = new DateTimeFormatError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('DateTimeFormatError: ' + cause.value, { cause }); } return write.readString8(); } diff --git a/ffi/capi/bindings/js/index.d.ts b/ffi/capi/bindings/js/index.d.ts index 84598eeeda0..2829e1f9954 100644 --- a/ffi/capi/bindings/js/index.d.ts +++ b/ffi/capi/bindings/js/index.d.ts @@ -224,12 +224,14 @@ export { CalendarParseError } from "./CalendarParseError" export { DataError } from "./DataError" -export { Error } from "./Error" +export { DateTimeFormatError } from "./DateTimeFormatError" export { FixedDecimalParseError } from "./FixedDecimalParseError" export { LocaleParseError } from "./LocaleParseError" +export { PatternLoadError } from "./PatternLoadError" + export { LocaleFallbackPriority } from "./LocaleFallbackPriority" export { FixedDecimalRoundingIncrement } from "./FixedDecimalRoundingIncrement" diff --git a/ffi/capi/bindings/js/index.mjs b/ffi/capi/bindings/js/index.mjs index 6badd4bfbbf..15e1f45cb8a 100644 --- a/ffi/capi/bindings/js/index.mjs +++ b/ffi/capi/bindings/js/index.mjs @@ -222,12 +222,14 @@ export { CalendarParseError } from "./CalendarParseError.mjs" export { DataError } from "./DataError.mjs" -export { Error } from "./Error.mjs" +export { DateTimeFormatError } from "./DateTimeFormatError.mjs" export { FixedDecimalParseError } from "./FixedDecimalParseError.mjs" export { LocaleParseError } from "./LocaleParseError.mjs" +export { PatternLoadError } from "./PatternLoadError.mjs" + export { LocaleFallbackPriority } from "./LocaleFallbackPriority.mjs" export { FixedDecimalRoundingIncrement } from "./FixedDecimalRoundingIncrement.mjs" diff --git a/ffi/capi/src/datetime_formatter.rs b/ffi/capi/src/datetime_formatter.rs index 1339fc4cf47..e9f6abcd551 100644 --- a/ffi/capi/src/datetime_formatter.rs +++ b/ffi/capi/src/datetime_formatter.rs @@ -15,7 +15,7 @@ pub mod ffi { use crate::{ date::ffi::{Date, IsoDate}, datetime::ffi::{DateTime, IsoDateTime}, - errors::ffi::Error, + errors::ffi::{DateTimeFormatError, PatternLoadError}, locale_core::ffi::Locale, provider::ffi::DataProvider, time::ffi::Time, @@ -44,7 +44,7 @@ pub mod ffi { provider: &DataProvider, locale: &Locale, length: DateTimeLength, - ) -> Result, Error> { + ) -> Result, PatternLoadError> { let locale = locale.to_datalocale(); let options = HM::with_length(NeoSkeletonLength::from(length)); @@ -60,7 +60,7 @@ pub mod ffi { /// Formats a [`Time`] to a string. pub fn format_time(&self, value: &Time, write: &mut diplomat_runtime::DiplomatWrite) { - let _infallible = self.0.format(&value.0).try_write_to(write); + let _lossy = self.0.format(&value.0).try_write_to(write); } /// Formats a [`DateTime`] to a string. @@ -69,7 +69,7 @@ pub mod ffi { value: &DateTime, write: &mut diplomat_runtime::DiplomatWrite, ) { - let _infallible = self.0.format(&value.0.time).try_write_to(write); + let _lossy = self.0.format(&value.0.time).try_write_to(write); } /// Formats a [`IsoDateTime`] to a string. @@ -78,7 +78,7 @@ pub mod ffi { value: &IsoDateTime, write: &mut diplomat_runtime::DiplomatWrite, ) { - let _infallible = self.0.format(&value.0.time).try_write_to(write); + let _lossy = self.0.format(&value.0.time).try_write_to(write); } } @@ -98,7 +98,7 @@ pub mod ffi { provider: &DataProvider, locale: &Locale, length: DateTimeLength, - ) -> Result, Error> { + ) -> Result, PatternLoadError> { let locale = locale.to_datalocale(); let options = YMD::with_length(NeoSkeletonLength::from(length)); @@ -119,7 +119,7 @@ pub mod ffi { write: &mut diplomat_runtime::DiplomatWrite, ) { let greg = icu_calendar::Date::new_from_iso(value.0, icu_calendar::Gregorian); - let _infallible = self.0.format(&greg).try_write_to(write); + let _lossy = self.0.format(&greg).try_write_to(write); } /// Formats a [`IsoDateTime`] to a string. pub fn format_iso_datetime( @@ -128,7 +128,7 @@ pub mod ffi { write: &mut diplomat_runtime::DiplomatWrite, ) { let greg = icu_calendar::DateTime::new_from_iso(value.0, icu_calendar::Gregorian); - let _infallible = self.0.format(&greg).try_write_to(write); + let _lossy = self.0.format(&greg).try_write_to(write); } } @@ -148,7 +148,7 @@ pub mod ffi { provider: &DataProvider, locale: &Locale, length: DateTimeLength, - ) -> Result, Error> { + ) -> Result, PatternLoadError> { let locale = locale.to_datalocale(); let options = YMDHM::with_length(NeoSkeletonLength::from(length)); @@ -169,7 +169,7 @@ pub mod ffi { write: &mut diplomat_runtime::DiplomatWrite, ) { let greg = icu_calendar::DateTime::new_from_iso(value.0, icu_calendar::Gregorian); - let _infallible = self.0.format(&greg).try_write_to(write); + let _lossy = self.0.format(&greg).try_write_to(write); } } @@ -187,7 +187,7 @@ pub mod ffi { provider: &DataProvider, locale: &Locale, length: DateTimeLength, - ) -> Result, Error> { + ) -> Result, PatternLoadError> { let locale = locale.to_datalocale(); let options = YMD::with_length(NeoSkeletonLength::from(length)); @@ -206,8 +206,8 @@ pub mod ffi { &self, value: &Date, write: &mut diplomat_runtime::DiplomatWrite, - ) -> Result<(), Error> { - let _infallible = self.0.convert_and_format(&value.0).try_write_to(write); + ) -> Result<(), DateTimeFormatError> { + let _lossy = self.0.convert_and_format(&value.0).try_write_to(write); Ok(()) } @@ -218,9 +218,9 @@ pub mod ffi { &self, value: &IsoDate, write: &mut diplomat_runtime::DiplomatWrite, - ) -> Result<(), Error> { + ) -> Result<(), DateTimeFormatError> { let any = value.0.to_any(); - let _infallible = self.0.convert_and_format(&any).try_write_to(write); + let _lossy = self.0.convert_and_format(&any).try_write_to(write); Ok(()) } @@ -229,8 +229,8 @@ pub mod ffi { &self, value: &DateTime, write: &mut diplomat_runtime::DiplomatWrite, - ) -> Result<(), Error> { - let _infallible = self.0.convert_and_format(&value.0).try_write_to(write); + ) -> Result<(), DateTimeFormatError> { + let _lossy = self.0.convert_and_format(&value.0).try_write_to(write); Ok(()) } @@ -241,9 +241,9 @@ pub mod ffi { &self, value: &IsoDateTime, write: &mut diplomat_runtime::DiplomatWrite, - ) -> Result<(), Error> { + ) -> Result<(), DateTimeFormatError> { let any = value.0.to_any(); - let _infallible = self.0.convert_and_format(&any).try_write_to(write); + let _lossy = self.0.convert_and_format(&any).try_write_to(write); Ok(()) } } @@ -262,7 +262,7 @@ pub mod ffi { provider: &DataProvider, locale: &Locale, length: DateTimeLength, - ) -> Result, Error> { + ) -> Result, PatternLoadError> { let locale = locale.to_datalocale(); let options = YMDHM::with_length(NeoSkeletonLength::from(length)); @@ -281,8 +281,8 @@ pub mod ffi { &self, value: &DateTime, write: &mut diplomat_runtime::DiplomatWrite, - ) -> Result<(), Error> { - let _infallible = self.0.convert_and_format(&value.0).try_write_to(write); + ) -> Result<(), DateTimeFormatError> { + let _lossy = self.0.convert_and_format(&value.0).try_write_to(write); Ok(()) } @@ -293,9 +293,9 @@ pub mod ffi { &self, value: &IsoDateTime, write: &mut diplomat_runtime::DiplomatWrite, - ) -> Result<(), Error> { + ) -> Result<(), DateTimeFormatError> { let any = value.0.to_any(); - let _infallible = self.0.convert_and_format(&any).try_write_to(write); + let _lossy = self.0.convert_and_format(&any).try_write_to(write); Ok(()) } } diff --git a/ffi/capi/src/errors.rs b/ffi/capi/src/errors.rs index 4fc3ca897a8..a4c2403d7e7 100644 --- a/ffi/capi/src/errors.rs +++ b/ffi/capi/src/errors.rs @@ -80,61 +80,40 @@ pub mod ffi { #[derive(Debug, PartialEq, Eq)] #[repr(C)] - /// Legacy error - // TODO(2.0): remove - #[diplomat::rust_link(icu::datetime::DateTimeError, Enum, compact)] - #[diplomat::rust_link(icu::datetime::MismatchedCalendarError, Struct, hidden)] + #[diplomat::rust_link(icu::datetime::PatternLoadError, Enum, compact)] #[diplomat::rust_link(icu::provider::DataError, Struct, compact)] #[diplomat::rust_link(icu::provider::DataErrorKind, Enum, compact)] - pub enum Error { - /// The error is not currently categorized as Error. - /// Please file a bug - UnknownError = 0x00, - - // general data errors - // See DataError - DataMissingDataMarkerError = 0x1_00, - DataMissingLocaleError = 0x1_02, - DataNeedsLocaleError = 0x1_04, - DataExtraneousLocaleError = 0x1_05, - DataFilteredResourceError = 0x1_06, - DataMismatchedTypeError = 0x1_07, - DataCustomError = 0x1_0A, - DataIoError = 0x1_0B, - DataUnavailableBufferFormatError = 0x1_0C, - - // datetime format errors - DateTimePatternError = 0x8_00, - DateTimeMissingInputFieldError = 0x8_01, - DateTimeSkeletonError = 0x8_02, - DateTimeUnsupportedFieldError = 0x8_03, - DateTimeUnsupportedOptionsError = 0x8_04, - DateTimeMissingWeekdaySymbolError = 0x8_05, - DateTimeMissingMonthSymbolError = 0x8_06, - DateTimeFixedDecimalError = 0x8_07, - DateTimeMismatchedCalendarError = 0x8_08, - DateTimeDuplicateFieldError = 0x8_09, - DateTimeTooNarrowError = 0x8_0A, - DateTimeMissingNamesError = 0x8_0B, - DateTimeZoneInfoMissingFieldsError = 0x8_80, // FFI-only error + pub enum PatternLoadError { + Unknown = 0x00, + + UnsupportedField = 0x8_03, + DuplicateField = 0x8_09, + TypeTooSpecific = 0x8_0A, + + DataMarkerNotFound = 0x01, + DataIdentifierNotFound = 0x02, + DataInvalidRequest = 0x03, + DataInconsistentData = 0x04, + DataDowncast = 0x05, + DataDeserialize = 0x06, + DataCustom = 0x07, + DataIo = 0x08, } -} -impl From for Error { - fn from(e: icu_provider::DataError) -> Self { - match e.kind { - icu_provider::DataErrorKind::MarkerNotFound => Error::DataMissingDataMarkerError, - icu_provider::DataErrorKind::IdentifierNotFound => Error::DataMissingLocaleError, - icu_provider::DataErrorKind::InvalidRequest => Error::DataExtraneousLocaleError, - icu_provider::DataErrorKind::Downcast(..) => Error::DataMismatchedTypeError, - icu_provider::DataErrorKind::Custom => Error::DataCustomError, - #[cfg(all( - feature = "provider_fs", - not(any(target_arch = "wasm32", target_os = "none")) - ))] - icu_provider::DataErrorKind::Io(..) => Error::DataIoError, - _ => Error::UnknownError, - } + // TODO: This type is currently never constructed, as all formatters perform lossy formatting. + #[derive(Debug, PartialEq, Eq)] + #[repr(C)] + #[diplomat::rust_link(icu::datetime::DateTimeWriteError, Enum, compact)] + pub enum DateTimeFormatError { + Unknown = 0x00, + MissingInputField = 0x01, + ZoneInfoMissingFields = 0x02, // FFI-only error + InvalidEra = 0x03, + InvalidMonthCode = 0x04, + InvalidCyclicYear = 0x05, + NamesNotLoaded = 0x10, + FixedDecimalFormatterNotLoaded = 0x11, + UnsupportedField = 0x12, } } @@ -191,15 +170,53 @@ impl From for CalendarParseError { } #[cfg(feature = "datetime")] -impl From for Error { - fn from(e: icu_datetime::LoadError) -> Self { +impl From for PatternLoadError { + fn from(e: icu_datetime::PatternLoadError) -> Self { match e { - icu_datetime::LoadError::DuplicateField(_) => Error::DateTimeDuplicateFieldError, - icu_datetime::LoadError::UnsupportedField(_) => Error::DateTimeUnsupportedFieldError, - icu_datetime::LoadError::TypeTooNarrow(_) => Error::DateTimeTooNarrowError, - icu_datetime::LoadError::Data(data_error) => data_error.into(), - icu_datetime::LoadError::MissingNames(_) => Error::DateTimeMissingNamesError, - _ => Error::UnknownError, + icu_datetime::PatternLoadError::ConflictingField(_) => Self::DuplicateField, + icu_datetime::PatternLoadError::UnsupportedField(_) => Self::UnsupportedField, + icu_datetime::PatternLoadError::TypeTooSpecific(_) => Self::TypeTooSpecific, + icu_datetime::PatternLoadError::Data(data_error) => data_error.into(), + _ => Self::Unknown, + } + } +} + +#[cfg(feature = "datetime")] +impl From for PatternLoadError { + fn from(e: icu_provider::DataError) -> Self { + match e.kind { + icu_provider::DataErrorKind::MarkerNotFound => Self::DataMarkerNotFound, + icu_provider::DataErrorKind::IdentifierNotFound => Self::DataIdentifierNotFound, + icu_provider::DataErrorKind::InvalidRequest => Self::DataInvalidRequest, + icu_provider::DataErrorKind::InconsistentData(..) => Self::DataInconsistentData, + icu_provider::DataErrorKind::Downcast(..) => Self::DataDowncast, + icu_provider::DataErrorKind::Deserialize => Self::DataDeserialize, + icu_provider::DataErrorKind::Custom => Self::DataCustom, + #[cfg(all( + feature = "provider_fs", + not(any(target_arch = "wasm32", target_os = "none")) + ))] + icu_provider::DataErrorKind::Io(..) => Self::DataIo, + _ => Self::Unknown, + } + } +} + +#[cfg(feature = "datetime")] +impl From for DateTimeFormatError { + fn from(value: icu_datetime::DateTimeWriteError) -> Self { + match value { + icu_datetime::DateTimeWriteError::MissingInputField(..) => Self::MissingInputField, + icu_datetime::DateTimeWriteError::InvalidEra(..) => Self::InvalidEra, + icu_datetime::DateTimeWriteError::InvalidMonthCode(..) => Self::InvalidMonthCode, + icu_datetime::DateTimeWriteError::InvalidCyclicYear { .. } => Self::InvalidCyclicYear, + icu_datetime::DateTimeWriteError::NamesNotLoaded(..) => Self::NamesNotLoaded, + icu_datetime::DateTimeWriteError::FixedDecimalFormatterNotLoaded => { + Self::FixedDecimalFormatterNotLoaded + } + icu_datetime::DateTimeWriteError::UnsupportedField(..) => Self::UnsupportedField, + _ => Self::Unknown, } } } diff --git a/ffi/capi/src/locale.rs b/ffi/capi/src/locale.rs index d7350e5530a..8119320a992 100644 --- a/ffi/capi/src/locale.rs +++ b/ffi/capi/src/locale.rs @@ -8,7 +8,7 @@ pub mod ffi { use alloc::boxed::Box; - use crate::errors::ffi::Error; + use crate::errors::ffi::DataError; use crate::locale_core::ffi::Locale; use crate::provider::ffi::DataProvider; @@ -28,7 +28,7 @@ pub mod ffi { /// Create a new [`LocaleCanonicalizer`]. #[diplomat::rust_link(icu::locale::LocaleCanonicalizer::new, FnInStruct)] #[diplomat::attr(supports = fallible_constructors, constructor)] - pub fn create(provider: &DataProvider) -> Result, Error> { + pub fn create(provider: &DataProvider) -> Result, DataError> { Ok(Box::new(LocaleCanonicalizer(call_constructor!( icu_locale::LocaleCanonicalizer::new [r => Ok(r)], icu_locale::LocaleCanonicalizer::try_new_with_any_provider, @@ -40,7 +40,9 @@ pub mod ffi { /// Create a new [`LocaleCanonicalizer`] with extended data. #[diplomat::rust_link(icu::locale::LocaleCanonicalizer::new_with_expander, FnInStruct)] #[diplomat::attr(supports = fallible_constructors, named_constructor = "extended")] - pub fn create_extended(provider: &DataProvider) -> Result, Error> { + pub fn create_extended( + provider: &DataProvider, + ) -> Result, DataError> { let expander = call_constructor!( icu_locale::LocaleExpander::new_extended [r => Ok(r)], icu_locale::LocaleExpander::try_new_with_any_provider, @@ -71,7 +73,7 @@ pub mod ffi { /// Create a new [`LocaleExpander`]. #[diplomat::rust_link(icu::locale::LocaleExpander::new, FnInStruct)] #[diplomat::attr(supports = fallible_constructors, constructor)] - pub fn create(provider: &DataProvider) -> Result, Error> { + pub fn create(provider: &DataProvider) -> Result, DataError> { Ok(Box::new(LocaleExpander(call_constructor!( icu_locale::LocaleExpander::new [r => Ok(r)], icu_locale::LocaleExpander::try_new_with_any_provider, @@ -83,7 +85,7 @@ pub mod ffi { /// Create a new [`LocaleExpander`] with extended data. #[diplomat::rust_link(icu::locale::LocaleExpander::new_extended, FnInStruct)] #[diplomat::attr(supports = fallible_constructors, named_constructor = "extended")] - pub fn create_extended(provider: &DataProvider) -> Result, Error> { + pub fn create_extended(provider: &DataProvider) -> Result, DataError> { Ok(Box::new(LocaleExpander(call_constructor!( icu_locale::LocaleExpander::new_extended [r => Ok(r)], icu_locale::LocaleExpander::try_new_with_any_provider, diff --git a/ffi/capi/src/zoned_formatter.rs b/ffi/capi/src/zoned_formatter.rs index 7fd47043b54..5a7c7ed8d5e 100644 --- a/ffi/capi/src/zoned_formatter.rs +++ b/ffi/capi/src/zoned_formatter.rs @@ -13,7 +13,7 @@ pub mod ffi { use crate::{ datetime::ffi::{DateTime, IsoDateTime}, datetime_formatter::ffi::DateTimeLength, - errors::ffi::Error, + errors::ffi::{DateTimeFormatError, PatternLoadError}, locale_core::ffi::Locale, provider::ffi::DataProvider, timezone::ffi::TimeZoneInfo, @@ -39,7 +39,7 @@ pub mod ffi { provider: &DataProvider, locale: &Locale, length: DateTimeLength, - ) -> Result, Error> { + ) -> Result, PatternLoadError> { let locale = locale.to_datalocale(); let options = YMDHMSV::with_length(NeoSkeletonLength::from(length)); @@ -61,7 +61,7 @@ pub mod ffi { datetime: &IsoDateTime, time_zone: &TimeZoneInfo, write: &mut diplomat_runtime::DiplomatWrite, - ) -> Result<(), Error> { + ) -> Result<(), DateTimeFormatError> { let greg = icu_calendar::DateTime::new_from_iso(datetime.0, icu_calendar::Gregorian); let zdt = icu_timezone::CustomZonedDateTime { date: greg.date, @@ -72,7 +72,7 @@ pub mod ffi { .at_time((datetime.0.date, datetime.0.time)) .with_zone_variant(time_zone.zone_variant.unwrap_or(ZoneVariant::Standard)), }; - let _infallible = self.0.format(&zdt).try_write_to(write); + let _lossy = self.0.format(&zdt).try_write_to(write); Ok(()) } } @@ -93,7 +93,7 @@ pub mod ffi { provider: &DataProvider, locale: &Locale, length: DateTimeLength, - ) -> Result, Error> { + ) -> Result, PatternLoadError> { let locale = locale.to_datalocale(); let options = YMDHMSV::with_length(NeoSkeletonLength::from(length)); @@ -113,7 +113,7 @@ pub mod ffi { datetime: &DateTime, time_zone: &TimeZoneInfo, write: &mut diplomat_runtime::DiplomatWrite, - ) -> Result<(), Error> { + ) -> Result<(), DateTimeFormatError> { let zdt = icu_timezone::CustomZonedDateTime { date: datetime.0.date.clone(), time: datetime.0.time, @@ -124,10 +124,10 @@ pub mod ffi { .with_zone_variant( time_zone .zone_variant - .ok_or(Error::DateTimeZoneInfoMissingFieldsError)?, + .ok_or(DateTimeFormatError::ZoneInfoMissingFields)?, ), }; - let _infallible = self.0.convert_and_format(&zdt).try_write_to(write); + let _lossy = self.0.convert_and_format(&zdt).try_write_to(write); Ok(()) } @@ -137,7 +137,7 @@ pub mod ffi { datetime: &IsoDateTime, time_zone: &TimeZoneInfo, write: &mut diplomat_runtime::DiplomatWrite, - ) -> Result<(), Error> { + ) -> Result<(), DateTimeFormatError> { let zdt = icu_timezone::CustomZonedDateTime { date: datetime.0.date, time: datetime.0.time, @@ -147,7 +147,7 @@ pub mod ffi { .at_time((datetime.0.date, datetime.0.time)) .with_zone_variant(time_zone.zone_variant.unwrap_or(ZoneVariant::Standard)), }; - let _infallible = self.0.convert_and_format(&zdt).try_write_to(write); + let _lossy = self.0.convert_and_format(&zdt).try_write_to(write); Ok(()) } } diff --git a/ffi/capi/tests/missing_apis.txt b/ffi/capi/tests/missing_apis.txt index 9abd89f28fd..415cf67b3c8 100644 --- a/ffi/capi/tests/missing_apis.txt +++ b/ffi/capi/tests/missing_apis.txt @@ -29,6 +29,7 @@ icu::datetime::FormattedNeoDateTime#Struct icu::datetime::FormattedNeoDateTime::pattern#FnInStruct icu::datetime::FormattedNeoDateTime::to_string_lossy#FnInStruct icu::datetime::FormattedNeoDateTime::try_write_to_parts#FnInStruct +icu::datetime::MismatchedCalendarError#Struct icu::datetime::NeoSkeletonLength#Enum icu::datetime::NeoSkeletonLength::into_option#FnInEnum icu::datetime::NeoSkeletonLength::to_date_style#FnInEnum diff --git a/tools/make/diplomat-coverage/src/allowlist.rs b/tools/make/diplomat-coverage/src/allowlist.rs index a3e4b640b0e..9bc0156f757 100644 --- a/tools/make/diplomat-coverage/src/allowlist.rs +++ b/tools/make/diplomat-coverage/src/allowlist.rs @@ -193,8 +193,6 @@ lazy_static::lazy_static! { "icu::datetime::options::components", "icu::datetime::options::preferences", "icu::datetime::DateTimeWriteError", - "icu::datetime::LoadError", - "icu::datetime::SingleLoadError", "icu::datetime::FormattedDateTimePattern", "icu::datetime::TypedDateTimeNames",