unicode-org / icu4x

Solving i18n for client-side and resource-constrained environments.
https://icu4x.unicode.org
Other
1.39k stars 178 forks source link

Make an `IxdtfParser` type #5736

Closed robertbastian closed 3 weeks ago

robertbastian commented 1 month ago

Based on #5735

robertbastian commented 4 weeks ago

Hmm, how do I load all AnyCalendar data upfront?

sffc commented 4 weeks ago

Just put in the bounds like usual:

https://unicode-org.github.io/icu4x/rustdoc/icu/calendar/enum.AnyCalendar.html#method.try_new_unstable

We do this in the DateTimeFormatter constructors, too (they are at the end of the list):

https://unicode-org.github.io/icu4x/rustdoc/icu/datetime/struct.DateTimeFormatter.html#method.try_new_unstable

sffc commented 4 weeks ago

Oh, since it is cross-crate, you will also need the AnyCalendarLoader thing.

sffc commented 4 weeks ago

Oh, but you don't know the calendar until parsing time. Hmm.

Easy way out is to pass the AnyCalendar provider into the parse function, but that's annoying.

Maybe you can save a closure that calls the AnyCalendar constructor as a field of the parser? You'd need to put a lifetime on the parser object, I think.

sffc commented 4 weeks ago

Or you could eagerly load all the markers into payloads and then make your own internal DataProvider that reads those payloads when calling AnyCalendar::try_new_unstable. Hmm. Maybe we want that to be a type in the icu_calendar crate, since it seems kind-of silly that AnyCalendar::new might need to load the same payload over and over, and you can't save it between loads.

https://github.com/unicode-org/icu4x/issues/5739

sffc commented 3 weeks ago

https://github.com/unicode-org/icu4x/pull/5740