zoned_time_formatter.rs (29038B)
1 // This file is part of ICU4X. For terms of use, please see the file 2 // called LICENSE at the top level of the ICU4X source tree 3 // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). 4 5 // @generated by tools/make/codegen/src/capi_datetime.rs 6 7 #[rustfmt::skip] 8 #[diplomat::bridge] 9 #[diplomat::abi_rename = "icu4x_{0}_mv1"] 10 #[diplomat::attr(auto, namespace = "icu4x")] 11 pub mod ffi { 12 use alloc::boxed::Box; 13 use writeable::TryWriteable; 14 15 #[allow(unused_imports)] 16 use crate::datetime_helpers::{self, map_or_default}; 17 18 #[allow(unused_imports)] 19 use crate::unstable::{ 20 date_formatter::ffi::{DateFormatter, DateFormatterGregorian}, 21 date_time_formatter::ffi::{DateTimeFormatter, DateTimeFormatterGregorian}, 22 date::ffi::IsoDate, 23 datetime_options::ffi::{DateTimeAlignment, DateTimeLength, TimePrecision}, 24 errors::ffi::DateTimeFormatterLoadError, 25 errors::ffi::DateTimeWriteError, 26 locale_core::ffi::Locale, 27 time_formatter::ffi::TimeFormatter, 28 time::ffi::Time, 29 timezone::ffi::TimeZoneInfo, 30 }; 31 32 #[cfg(feature = "buffer_provider")] 33 use crate::unstable::provider::ffi::DataProvider; 34 35 #[diplomat::opaque] 36 #[diplomat::rust_link(icu::datetime::NoCalendarFormatter, Typedef)] 37 pub struct ZonedTimeFormatter( 38 pub icu_datetime::FixedCalendarDateTimeFormatter< 39 (), 40 icu_datetime::fieldsets::enums::ZonedTimeFieldSet 41 >, 42 ); 43 44 impl ZonedTimeFormatter { 45 /// Creates a zoned formatter based on a non-zoned formatter. 46 /// 47 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 48 /// or else unexpected behavior may occur! 49 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_long")] 50 #[diplomat::rust_link(icu::datetime::fieldsets::zone::SpecificLong, Struct)] 51 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 52 #[cfg(feature = "compiled_data")] 53 pub fn create_specific_long( 54 locale: &Locale, 55 length: Option<DateTimeLength>, 56 time_precision: Option<TimePrecision>, 57 alignment: Option<DateTimeAlignment>, 58 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 59 let zone = icu_datetime::fieldsets::zone::SpecificLong; 60 let prefs = (&locale.0).into(); 61 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 62 options.time_precision = time_precision.map(Into::into); 63 options.alignment = alignment.map(Into::into); 64 let options = options.with_zone(zone); 65 Ok(Box::new(Self( 66 icu_datetime 67 ::FixedCalendarDateTimeFormatter 68 ::try_new( 69 prefs, 70 options 71 )? 72 .cast_into_fset(), 73 ))) 74 } 75 76 /// Creates a zoned formatter based on a non-zoned formatter. 77 /// 78 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 79 /// or else unexpected behavior may occur! 80 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_long_with_provider")] 81 #[diplomat::rust_link(icu::datetime::fieldsets::zone::SpecificLong, Struct)] 82 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 83 #[cfg(feature = "buffer_provider")] 84 pub fn create_specific_long_with_provider( 85 provider: &DataProvider, 86 locale: &Locale, 87 length: Option<DateTimeLength>, 88 time_precision: Option<TimePrecision>, 89 alignment: Option<DateTimeAlignment>, 90 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 91 let provider = provider.get()?; 92 let zone = icu_datetime::fieldsets::zone::SpecificLong; 93 let prefs = (&locale.0).into(); 94 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 95 options.time_precision = time_precision.map(Into::into); 96 options.alignment = alignment.map(Into::into); 97 let options = options.with_zone(zone); 98 Ok(Box::new(Self( 99 icu_datetime 100 ::FixedCalendarDateTimeFormatter 101 ::try_new_with_buffer_provider( 102 provider, 103 prefs, 104 options 105 )? 106 .cast_into_fset(), 107 ))) 108 } 109 110 /// Creates a zoned formatter based on a non-zoned formatter. 111 /// 112 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 113 /// or else unexpected behavior may occur! 114 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_short")] 115 #[diplomat::rust_link(icu::datetime::fieldsets::zone::SpecificShort, Struct)] 116 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 117 #[cfg(feature = "compiled_data")] 118 pub fn create_specific_short( 119 locale: &Locale, 120 length: Option<DateTimeLength>, 121 time_precision: Option<TimePrecision>, 122 alignment: Option<DateTimeAlignment>, 123 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 124 let zone = icu_datetime::fieldsets::zone::SpecificShort; 125 let prefs = (&locale.0).into(); 126 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 127 options.time_precision = time_precision.map(Into::into); 128 options.alignment = alignment.map(Into::into); 129 let options = options.with_zone(zone); 130 Ok(Box::new(Self( 131 icu_datetime 132 ::FixedCalendarDateTimeFormatter 133 ::try_new( 134 prefs, 135 options 136 )? 137 .cast_into_fset(), 138 ))) 139 } 140 141 /// Creates a zoned formatter based on a non-zoned formatter. 142 /// 143 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 144 /// or else unexpected behavior may occur! 145 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_short_with_provider")] 146 #[diplomat::rust_link(icu::datetime::fieldsets::zone::SpecificShort, Struct)] 147 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 148 #[cfg(feature = "buffer_provider")] 149 pub fn create_specific_short_with_provider( 150 provider: &DataProvider, 151 locale: &Locale, 152 length: Option<DateTimeLength>, 153 time_precision: Option<TimePrecision>, 154 alignment: Option<DateTimeAlignment>, 155 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 156 let provider = provider.get()?; 157 let zone = icu_datetime::fieldsets::zone::SpecificShort; 158 let prefs = (&locale.0).into(); 159 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 160 options.time_precision = time_precision.map(Into::into); 161 options.alignment = alignment.map(Into::into); 162 let options = options.with_zone(zone); 163 Ok(Box::new(Self( 164 icu_datetime 165 ::FixedCalendarDateTimeFormatter 166 ::try_new_with_buffer_provider( 167 provider, 168 prefs, 169 options 170 )? 171 .cast_into_fset(), 172 ))) 173 } 174 175 /// Creates a zoned formatter based on a non-zoned formatter. 176 /// 177 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 178 /// or else unexpected behavior may occur! 179 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_long")] 180 #[diplomat::rust_link(icu::datetime::fieldsets::zone::LocalizedOffsetLong, Struct)] 181 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 182 #[cfg(feature = "compiled_data")] 183 pub fn create_localized_offset_long( 184 locale: &Locale, 185 length: Option<DateTimeLength>, 186 time_precision: Option<TimePrecision>, 187 alignment: Option<DateTimeAlignment>, 188 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 189 let zone = icu_datetime::fieldsets::zone::LocalizedOffsetLong; 190 let prefs = (&locale.0).into(); 191 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 192 options.time_precision = time_precision.map(Into::into); 193 options.alignment = alignment.map(Into::into); 194 let options = options.with_zone(zone); 195 Ok(Box::new(Self( 196 icu_datetime 197 ::FixedCalendarDateTimeFormatter 198 ::try_new( 199 prefs, 200 options 201 )? 202 .cast_into_fset(), 203 ))) 204 } 205 206 /// Creates a zoned formatter based on a non-zoned formatter. 207 /// 208 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 209 /// or else unexpected behavior may occur! 210 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_long_with_provider")] 211 #[diplomat::rust_link(icu::datetime::fieldsets::zone::LocalizedOffsetLong, Struct)] 212 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 213 #[cfg(feature = "buffer_provider")] 214 pub fn create_localized_offset_long_with_provider( 215 provider: &DataProvider, 216 locale: &Locale, 217 length: Option<DateTimeLength>, 218 time_precision: Option<TimePrecision>, 219 alignment: Option<DateTimeAlignment>, 220 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 221 let provider = provider.get()?; 222 let zone = icu_datetime::fieldsets::zone::LocalizedOffsetLong; 223 let prefs = (&locale.0).into(); 224 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 225 options.time_precision = time_precision.map(Into::into); 226 options.alignment = alignment.map(Into::into); 227 let options = options.with_zone(zone); 228 Ok(Box::new(Self( 229 icu_datetime 230 ::FixedCalendarDateTimeFormatter 231 ::try_new_with_buffer_provider( 232 provider, 233 prefs, 234 options 235 )? 236 .cast_into_fset(), 237 ))) 238 } 239 240 /// Creates a zoned formatter based on a non-zoned formatter. 241 /// 242 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 243 /// or else unexpected behavior may occur! 244 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_short")] 245 #[diplomat::rust_link(icu::datetime::fieldsets::zone::LocalizedOffsetShort, Struct)] 246 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 247 #[cfg(feature = "compiled_data")] 248 pub fn create_localized_offset_short( 249 locale: &Locale, 250 length: Option<DateTimeLength>, 251 time_precision: Option<TimePrecision>, 252 alignment: Option<DateTimeAlignment>, 253 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 254 let zone = icu_datetime::fieldsets::zone::LocalizedOffsetShort; 255 let prefs = (&locale.0).into(); 256 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 257 options.time_precision = time_precision.map(Into::into); 258 options.alignment = alignment.map(Into::into); 259 let options = options.with_zone(zone); 260 Ok(Box::new(Self( 261 icu_datetime 262 ::FixedCalendarDateTimeFormatter 263 ::try_new( 264 prefs, 265 options 266 )? 267 .cast_into_fset(), 268 ))) 269 } 270 271 /// Creates a zoned formatter based on a non-zoned formatter. 272 /// 273 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 274 /// or else unexpected behavior may occur! 275 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_short_with_provider")] 276 #[diplomat::rust_link(icu::datetime::fieldsets::zone::LocalizedOffsetShort, Struct)] 277 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 278 #[cfg(feature = "buffer_provider")] 279 pub fn create_localized_offset_short_with_provider( 280 provider: &DataProvider, 281 locale: &Locale, 282 length: Option<DateTimeLength>, 283 time_precision: Option<TimePrecision>, 284 alignment: Option<DateTimeAlignment>, 285 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 286 let provider = provider.get()?; 287 let zone = icu_datetime::fieldsets::zone::LocalizedOffsetShort; 288 let prefs = (&locale.0).into(); 289 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 290 options.time_precision = time_precision.map(Into::into); 291 options.alignment = alignment.map(Into::into); 292 let options = options.with_zone(zone); 293 Ok(Box::new(Self( 294 icu_datetime 295 ::FixedCalendarDateTimeFormatter 296 ::try_new_with_buffer_provider( 297 provider, 298 prefs, 299 options 300 )? 301 .cast_into_fset(), 302 ))) 303 } 304 305 /// Creates a zoned formatter based on a non-zoned formatter. 306 /// 307 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 308 /// or else unexpected behavior may occur! 309 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_long")] 310 #[diplomat::rust_link(icu::datetime::fieldsets::zone::GenericLong, Struct)] 311 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 312 #[cfg(feature = "compiled_data")] 313 pub fn create_generic_long( 314 locale: &Locale, 315 length: Option<DateTimeLength>, 316 time_precision: Option<TimePrecision>, 317 alignment: Option<DateTimeAlignment>, 318 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 319 let zone = icu_datetime::fieldsets::zone::GenericLong; 320 let prefs = (&locale.0).into(); 321 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 322 options.time_precision = time_precision.map(Into::into); 323 options.alignment = alignment.map(Into::into); 324 let options = options.with_zone(zone); 325 Ok(Box::new(Self( 326 icu_datetime 327 ::FixedCalendarDateTimeFormatter 328 ::try_new( 329 prefs, 330 options 331 )? 332 .cast_into_fset(), 333 ))) 334 } 335 336 /// Creates a zoned formatter based on a non-zoned formatter. 337 /// 338 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 339 /// or else unexpected behavior may occur! 340 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_long_with_provider")] 341 #[diplomat::rust_link(icu::datetime::fieldsets::zone::GenericLong, Struct)] 342 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 343 #[cfg(feature = "buffer_provider")] 344 pub fn create_generic_long_with_provider( 345 provider: &DataProvider, 346 locale: &Locale, 347 length: Option<DateTimeLength>, 348 time_precision: Option<TimePrecision>, 349 alignment: Option<DateTimeAlignment>, 350 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 351 let provider = provider.get()?; 352 let zone = icu_datetime::fieldsets::zone::GenericLong; 353 let prefs = (&locale.0).into(); 354 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 355 options.time_precision = time_precision.map(Into::into); 356 options.alignment = alignment.map(Into::into); 357 let options = options.with_zone(zone); 358 Ok(Box::new(Self( 359 icu_datetime 360 ::FixedCalendarDateTimeFormatter 361 ::try_new_with_buffer_provider( 362 provider, 363 prefs, 364 options 365 )? 366 .cast_into_fset(), 367 ))) 368 } 369 370 /// Creates a zoned formatter based on a non-zoned formatter. 371 /// 372 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 373 /// or else unexpected behavior may occur! 374 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_short")] 375 #[diplomat::rust_link(icu::datetime::fieldsets::zone::GenericShort, Struct)] 376 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 377 #[diplomat::demo(default_constructor)] 378 #[cfg(feature = "compiled_data")] 379 pub fn create_generic_short( 380 locale: &Locale, 381 length: Option<DateTimeLength>, 382 time_precision: Option<TimePrecision>, 383 alignment: Option<DateTimeAlignment>, 384 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 385 let zone = icu_datetime::fieldsets::zone::GenericShort; 386 let prefs = (&locale.0).into(); 387 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 388 options.time_precision = time_precision.map(Into::into); 389 options.alignment = alignment.map(Into::into); 390 let options = options.with_zone(zone); 391 Ok(Box::new(Self( 392 icu_datetime 393 ::FixedCalendarDateTimeFormatter 394 ::try_new( 395 prefs, 396 options 397 )? 398 .cast_into_fset(), 399 ))) 400 } 401 402 /// Creates a zoned formatter based on a non-zoned formatter. 403 /// 404 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 405 /// or else unexpected behavior may occur! 406 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_short_with_provider")] 407 #[diplomat::rust_link(icu::datetime::fieldsets::zone::GenericShort, Struct)] 408 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 409 #[cfg(feature = "buffer_provider")] 410 pub fn create_generic_short_with_provider( 411 provider: &DataProvider, 412 locale: &Locale, 413 length: Option<DateTimeLength>, 414 time_precision: Option<TimePrecision>, 415 alignment: Option<DateTimeAlignment>, 416 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 417 let provider = provider.get()?; 418 let zone = icu_datetime::fieldsets::zone::GenericShort; 419 let prefs = (&locale.0).into(); 420 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 421 options.time_precision = time_precision.map(Into::into); 422 options.alignment = alignment.map(Into::into); 423 let options = options.with_zone(zone); 424 Ok(Box::new(Self( 425 icu_datetime 426 ::FixedCalendarDateTimeFormatter 427 ::try_new_with_buffer_provider( 428 provider, 429 prefs, 430 options 431 )? 432 .cast_into_fset(), 433 ))) 434 } 435 436 /// Creates a zoned formatter based on a non-zoned formatter. 437 /// 438 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 439 /// or else unexpected behavior may occur! 440 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "location")] 441 #[diplomat::rust_link(icu::datetime::fieldsets::zone::Location, Struct)] 442 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 443 #[cfg(feature = "compiled_data")] 444 pub fn create_location( 445 locale: &Locale, 446 length: Option<DateTimeLength>, 447 time_precision: Option<TimePrecision>, 448 alignment: Option<DateTimeAlignment>, 449 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 450 let zone = icu_datetime::fieldsets::zone::Location; 451 let prefs = (&locale.0).into(); 452 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 453 options.time_precision = time_precision.map(Into::into); 454 options.alignment = alignment.map(Into::into); 455 let options = options.with_zone(zone); 456 Ok(Box::new(Self( 457 icu_datetime 458 ::FixedCalendarDateTimeFormatter 459 ::try_new( 460 prefs, 461 options 462 )? 463 .cast_into_fset(), 464 ))) 465 } 466 467 /// Creates a zoned formatter based on a non-zoned formatter. 468 /// 469 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 470 /// or else unexpected behavior may occur! 471 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "location_with_provider")] 472 #[diplomat::rust_link(icu::datetime::fieldsets::zone::Location, Struct)] 473 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 474 #[cfg(feature = "buffer_provider")] 475 pub fn create_location_with_provider( 476 provider: &DataProvider, 477 locale: &Locale, 478 length: Option<DateTimeLength>, 479 time_precision: Option<TimePrecision>, 480 alignment: Option<DateTimeAlignment>, 481 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 482 let provider = provider.get()?; 483 let zone = icu_datetime::fieldsets::zone::Location; 484 let prefs = (&locale.0).into(); 485 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 486 options.time_precision = time_precision.map(Into::into); 487 options.alignment = alignment.map(Into::into); 488 let options = options.with_zone(zone); 489 Ok(Box::new(Self( 490 icu_datetime 491 ::FixedCalendarDateTimeFormatter 492 ::try_new_with_buffer_provider( 493 provider, 494 prefs, 495 options 496 )? 497 .cast_into_fset(), 498 ))) 499 } 500 501 /// Creates a zoned formatter based on a non-zoned formatter. 502 /// 503 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 504 /// or else unexpected behavior may occur! 505 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "exemplar_city")] 506 #[diplomat::rust_link(icu::datetime::fieldsets::zone::ExemplarCity, Struct)] 507 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 508 #[cfg(feature = "compiled_data")] 509 pub fn create_exemplar_city( 510 locale: &Locale, 511 length: Option<DateTimeLength>, 512 time_precision: Option<TimePrecision>, 513 alignment: Option<DateTimeAlignment>, 514 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 515 let zone = icu_datetime::fieldsets::zone::ExemplarCity; 516 let prefs = (&locale.0).into(); 517 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 518 options.time_precision = time_precision.map(Into::into); 519 options.alignment = alignment.map(Into::into); 520 let options = options.with_zone(zone); 521 Ok(Box::new(Self( 522 icu_datetime 523 ::FixedCalendarDateTimeFormatter 524 ::try_new( 525 prefs, 526 options 527 )? 528 .cast_into_fset(), 529 ))) 530 } 531 532 /// Creates a zoned formatter based on a non-zoned formatter. 533 /// 534 /// Caution: The locale provided here must match the locale used to construct the non-zoned formatter, 535 /// or else unexpected behavior may occur! 536 #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "exemplar_city_with_provider")] 537 #[diplomat::rust_link(icu::datetime::fieldsets::zone::ExemplarCity, Struct)] 538 #[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)] 539 #[cfg(feature = "buffer_provider")] 540 pub fn create_exemplar_city_with_provider( 541 provider: &DataProvider, 542 locale: &Locale, 543 length: Option<DateTimeLength>, 544 time_precision: Option<TimePrecision>, 545 alignment: Option<DateTimeAlignment>, 546 ) -> Result<Box<Self>, DateTimeFormatterLoadError> { 547 let provider = provider.get()?; 548 let zone = icu_datetime::fieldsets::zone::ExemplarCity; 549 let prefs = (&locale.0).into(); 550 let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length)); 551 options.time_precision = time_precision.map(Into::into); 552 options.alignment = alignment.map(Into::into); 553 let options = options.with_zone(zone); 554 Ok(Box::new(Self( 555 icu_datetime 556 ::FixedCalendarDateTimeFormatter 557 ::try_new_with_buffer_provider( 558 provider, 559 prefs, 560 options 561 )? 562 .cast_into_fset(), 563 ))) 564 } 565 566 #[diplomat::rust_link(icu::datetime::FixedCalendarDateTimeFormatter::format, FnInStruct)] 567 #[diplomat::rust_link(icu::datetime::FormattedDateTime, Struct, hidden)] 568 #[diplomat::rust_link(icu::datetime::FormattedDateTime::to_string, FnInStruct, hidden)] 569 pub fn format( 570 &self, 571 time: &Time, 572 zone: &TimeZoneInfo, 573 write: &mut diplomat_runtime::DiplomatWrite, 574 ) -> Result<(), DateTimeWriteError> { 575 let mut input = icu_datetime::unchecked::DateTimeInputUnchecked::default(); 576 input.set_time_fields(time.0); 577 input.set_time_zone_id(zone.id); 578 if let Some(offset) = zone.offset { 579 input.set_time_zone_utc_offset(offset); 580 } 581 if let Some(zone_name_timestamp) = zone.zone_name_timestamp { 582 input.set_time_zone_name_timestamp(zone_name_timestamp); 583 } 584 else { 585 input.set_time_zone_name_timestamp(icu_time::zone::ZoneNameTimestamp::far_in_future()) 586 } 587 if let Some(variant) = zone.variant { 588 input.set_time_zone_variant(variant); 589 } 590 let _infallible = self 591 .0 592 .format_unchecked(input) 593 .try_write_to(write) 594 .ok() 595 .transpose()?; 596 Ok(()) 597 } 598 } 599 600 }