@@ -174,6 +174,20 @@ pub struct NeoOptions<R: DateTimeMarkers> {
174
174
pub fractional_second_digits : R :: FractionalSecondDigitsOption ,
175
175
}
176
176
177
+ impl < R > From < NeoOptions < R > > for RawNeoOptions
178
+ where
179
+ R : DateTimeMarkers ,
180
+ {
181
+ fn from ( options : NeoOptions < R > ) -> Self {
182
+ Self {
183
+ length : options. length . into ( ) ,
184
+ alignment : options. alignment . into ( ) ,
185
+ era_display : options. era_display . into ( ) ,
186
+ fractional_second_digits : options. fractional_second_digits . into ( ) ,
187
+ }
188
+ }
189
+ }
190
+
177
191
impl < R > From < NeoSkeletonLength > for NeoOptions < R >
178
192
where
179
193
R : DateTimeMarkers ,
@@ -214,6 +228,28 @@ where
214
228
}
215
229
}
216
230
231
+ impl RawNeoOptions {
232
+ #[ cfg( feature = "compiled_data" ) ]
233
+ pub ( crate ) fn from_field_set < FSet > ( field_set : FSet ) -> Self
234
+ where
235
+ FSet : DateTimeMarkers ,
236
+ FSet : NeoGetField < FSet :: LengthOption > ,
237
+ FSet : NeoGetField < FSet :: AlignmentOption > ,
238
+ FSet : NeoGetField < FSet :: EraDisplayOption > ,
239
+ FSet : NeoGetField < FSet :: FractionalSecondDigitsOption > ,
240
+ {
241
+ Self {
242
+ length : NeoGetField :: < FSet :: LengthOption > :: get_field ( & field_set) . into ( ) ,
243
+ alignment : NeoGetField :: < FSet :: AlignmentOption > :: get_field ( & field_set) . into ( ) ,
244
+ era_display : NeoGetField :: < FSet :: EraDisplayOption > :: get_field ( & field_set) . into ( ) ,
245
+ fractional_second_digits : NeoGetField :: < FSet :: FractionalSecondDigitsOption > :: get_field (
246
+ & field_set,
247
+ )
248
+ . into ( ) ,
249
+ }
250
+ }
251
+ }
252
+
217
253
size_test ! ( TypedNeoFormatter <icu_calendar:: Gregorian , crate :: neo_marker:: NeoYearMonthDayMarker >, typed_neo_year_month_day_formatter_size, 504 ) ;
218
254
219
255
/// [`TypedNeoFormatter`] is a formatter capable of formatting dates and/or times from
@@ -229,6 +265,78 @@ pub struct TypedNeoFormatter<C: CldrCalendar, R: DateTimeNamesMarker> {
229
265
_calendar : PhantomData < C > ,
230
266
}
231
267
268
+ impl < C : CldrCalendar , FSet : DateTimeMarkers + HasConstComponents > TypedNeoFormatter < C , FSet >
269
+ where
270
+ FSet :: D : TypedDateDataMarkers < C > ,
271
+ FSet :: T : TimeMarkers ,
272
+ FSet :: Z : ZoneMarkers ,
273
+ FSet : NeoGetField < FSet :: LengthOption > ,
274
+ FSet : NeoGetField < FSet :: AlignmentOption > ,
275
+ FSet : NeoGetField < FSet :: EraDisplayOption > ,
276
+ FSet : NeoGetField < FSet :: FractionalSecondDigitsOption > ,
277
+ {
278
+ /// Creates a new [`TypedNeoFormatter`] from compiled data with
279
+ /// datetime components specified at build time.
280
+ ///
281
+ /// Use this constructor for optimal data size and memory use
282
+ /// if you know the required datetime components at build time.
283
+ /// If you do not know the datetime components until runtime,
284
+ /// use a `with_components` constructor.
285
+ ///
286
+ /// # Examples
287
+ ///
288
+ /// Basic usage:
289
+ ///
290
+ /// ```
291
+ /// use icu::calendar::Date;
292
+ /// use icu::calendar::Gregorian;
293
+ /// use icu::datetime::neo::TypedNeoFormatter;
294
+ /// use icu::datetime::neo_marker::NeoYearMonthDayMarker;
295
+ /// use icu::datetime::neo_skeleton::NeoSkeletonLength;
296
+ /// use icu::locale::locale;
297
+ /// use writeable::assert_try_writeable_eq;
298
+ ///
299
+ /// let formatter =
300
+ /// TypedNeoFormatter::try_new2(
301
+ /// &locale!("es-MX").into(),
302
+ /// NeoYearMonthDayMarker::with_length(NeoSkeletonLength::Long),
303
+ /// )
304
+ /// .unwrap();
305
+ ///
306
+ /// assert_try_writeable_eq!(
307
+ /// formatter.format(&Date::try_new_gregorian_date(2023, 12, 20).unwrap()),
308
+ /// "20 de diciembre de 2023"
309
+ /// );
310
+ /// ```
311
+ #[ cfg( feature = "compiled_data" ) ]
312
+ pub fn try_new2 ( locale : & DataLocale , options : FSet ) -> Result < Self , LoadError >
313
+ where
314
+ crate :: provider:: Baked : Sized
315
+ // Date formatting markers
316
+ + DataProvider < <FSet :: D as TypedDateDataMarkers < C > >:: YearNamesV1Marker >
317
+ + DataProvider < <FSet :: D as TypedDateDataMarkers < C > >:: MonthNamesV1Marker >
318
+ + DataProvider < <FSet :: D as TypedDateDataMarkers < C > >:: DateSkeletonPatternsV1Marker >
319
+ + DataProvider < <FSet :: D as TypedDateDataMarkers < C > >:: WeekdayNamesV1Marker >
320
+ + DataProvider < <FSet :: T as TimeMarkers >:: DayPeriodNamesV1Marker >
321
+ + DataProvider < <FSet :: T as TimeMarkers >:: TimeSkeletonPatternsV1Marker >
322
+ + DataProvider < <FSet :: Z as ZoneMarkers >:: EssentialsV1Marker >
323
+ + DataProvider < <FSet :: Z as ZoneMarkers >:: ExemplarCitiesV1Marker >
324
+ + DataProvider < <FSet :: Z as ZoneMarkers >:: GenericLongV1Marker >
325
+ + DataProvider < <FSet :: Z as ZoneMarkers >:: GenericShortV1Marker >
326
+ + DataProvider < <FSet :: Z as ZoneMarkers >:: SpecificLongV1Marker >
327
+ + DataProvider < <FSet :: Z as ZoneMarkers >:: SpecificShortV1Marker >
328
+ + DataProvider < FSet :: GluePatternV1Marker > ,
329
+ {
330
+ Self :: try_new_internal (
331
+ & crate :: provider:: Baked ,
332
+ & ExternalLoaderCompiledData ,
333
+ locale,
334
+ FSet :: COMPONENTS ,
335
+ RawNeoOptions :: from_field_set ( options) ,
336
+ )
337
+ }
338
+ }
339
+
232
340
impl < C : CldrCalendar , R : DateTimeMarkers + HasConstComponents > TypedNeoFormatter < C , R >
233
341
where
234
342
R :: D : TypedDateDataMarkers < C > ,
@@ -292,7 +400,7 @@ where
292
400
& ExternalLoaderCompiledData ,
293
401
locale,
294
402
R :: COMPONENTS ,
295
- options,
403
+ options. into ( ) ,
296
404
)
297
405
}
298
406
@@ -337,7 +445,7 @@ where
337
445
& ExternalLoaderUnstable ( provider) ,
338
446
locale,
339
447
R :: COMPONENTS ,
340
- options,
448
+ options. into ( ) ,
341
449
)
342
450
}
343
451
}
@@ -459,7 +567,7 @@ where
459
567
& ExternalLoaderCompiledData ,
460
568
locale,
461
569
components. into ( ) ,
462
- options,
570
+ options. into ( ) ,
463
571
)
464
572
}
465
573
@@ -505,7 +613,7 @@ where
505
613
& ExternalLoaderUnstable ( provider) ,
506
614
locale,
507
615
components. into ( ) ,
508
- options,
616
+ options. into ( ) ,
509
617
)
510
618
}
511
619
}
@@ -521,7 +629,7 @@ where
521
629
loader : & L ,
522
630
locale : & DataLocale ,
523
631
components : NeoComponents ,
524
- options : NeoOptions < R > ,
632
+ options : RawNeoOptions ,
525
633
) -> Result < Self , LoadError >
526
634
where
527
635
P : ?Sized
@@ -550,11 +658,8 @@ where
550
658
& <R :: T as TimeMarkers >:: TimeSkeletonPatternsV1Marker :: bind ( provider) ,
551
659
& R :: GluePatternV1Marker :: bind ( provider) ,
552
660
locale,
553
- options. length . into ( ) ,
554
661
components,
555
- options. alignment . into ( ) ,
556
- options. era_display . into ( ) ,
557
- options. fractional_second_digits . into ( ) ,
662
+ options,
558
663
hour_cycle,
559
664
)
560
665
. map_err ( LoadError :: Data ) ?;
@@ -790,7 +895,7 @@ where
790
895
& ExternalLoaderCompiledData ,
791
896
locale,
792
897
R :: COMPONENTS ,
793
- options,
898
+ options. into ( ) ,
794
899
)
795
900
}
796
901
@@ -890,7 +995,7 @@ where
890
995
& ExternalLoaderUnstable ( provider) ,
891
996
locale,
892
997
R :: COMPONENTS ,
893
- options,
998
+ options. into ( ) ,
894
999
)
895
1000
}
896
1001
}
@@ -1055,7 +1160,7 @@ where
1055
1160
& ExternalLoaderCompiledData ,
1056
1161
locale,
1057
1162
components. into ( ) ,
1058
- options,
1163
+ options. into ( ) ,
1059
1164
)
1060
1165
}
1061
1166
@@ -1156,7 +1261,7 @@ where
1156
1261
& ExternalLoaderUnstable ( provider) ,
1157
1262
locale,
1158
1263
components. into ( ) ,
1159
- options,
1264
+ options. into ( ) ,
1160
1265
)
1161
1266
}
1162
1267
}
@@ -1172,7 +1277,7 @@ where
1172
1277
loader : & L ,
1173
1278
locale : & DataLocale ,
1174
1279
components : NeoComponents ,
1175
- options : NeoOptions < R > ,
1280
+ options : RawNeoOptions ,
1176
1281
) -> Result < Self , LoadError >
1177
1282
where
1178
1283
P : ?Sized
@@ -1251,11 +1356,8 @@ where
1251
1356
& <R :: T as TimeMarkers >:: TimeSkeletonPatternsV1Marker :: bind ( provider) ,
1252
1357
& R :: GluePatternV1Marker :: bind ( provider) ,
1253
1358
locale,
1254
- options. length . into ( ) ,
1255
1359
components,
1256
- options. alignment . into ( ) ,
1257
- options. era_display . into ( ) ,
1258
- options. fractional_second_digits . into ( ) ,
1360
+ options,
1259
1361
hour_cycle,
1260
1362
)
1261
1363
. map_err ( LoadError :: Data ) ?;
0 commit comments