Expand description
Builder APIs for dynamic field sets.
These APIs are designed for when the field set is not known at compile time. This could happen if:
- The field set is sent over the network or read from a data file
- Implementing another interface with different types
If the field set is known at compile time, use the static fieldset APIs instead of the builder exported in this module.
A field set builder can be serialized with the right set of Cargo features.
All examples below will show both ways to build a field set.
§Examples
use icu::datetime::fieldsets;
use icu::datetime::fieldsets::builder::*;
use icu::datetime::fieldsets::enums::*;
use icu::datetime::options::*;
// Year, Month, Day
// Medium length
// Always display the era
let static_field_set =
fieldsets::YMD::medium().with_year_style(YearStyle::WithEra);
let mut builder = FieldSetBuilder::new();
builder.date_fields = Some(DateFields::YMD);
builder.length = Some(Length::Medium);
builder.year_style = Some(YearStyle::WithEra);
let dynamic_field_set = builder.build_date().unwrap();
assert_eq!(dynamic_field_set, DateFieldSet::YMD(static_field_set),);
// Standalone Month
// Long length
let static_field_set = fieldsets::M::long();
let mut builder = FieldSetBuilder::new();
builder.length = Some(Length::Long);
builder.date_fields = Some(DateFields::M);
let dynamic_field_set = builder.build_calendar_period().unwrap();
assert_eq!(
dynamic_field_set,
CalendarPeriodFieldSet::M(static_field_set),
);
// Weekday and Time of day
// Medium length, implicit in the builder
// Display time to the minute
let static_field_set =
fieldsets::ET::medium().with_time_precision(TimePrecision::Minute);
let mut builder = FieldSetBuilder::new();
builder.date_fields = Some(DateFields::E);
builder.time_precision = Some(TimePrecision::Minute);
let dynamic_field_set = builder.build_date_and_time().unwrap();
assert_eq!(dynamic_field_set, DateAndTimeFieldSet::ET(static_field_set),);
// Time and Time Zone
// Short length
// Long specific non-location time zone
// Display time to the millisecond
// Render for column alignment
let static_field_set = fieldsets::T::short()
.with_time_precision(TimePrecision::Subsecond(SubsecondDigits::S3))
.with_alignment(Alignment::Column)
.zone(fieldsets::zone::SpecificLong);
let mut builder = FieldSetBuilder::new();
builder.length = Some(Length::Short);
builder.time_precision =
Some(TimePrecision::Subsecond(SubsecondDigits::S3));
builder.alignment = Some(Alignment::Column);
builder.zone_style = Some(ZoneStyle::SpecificLong);
let dynamic_field_set = builder.build_composite().unwrap();
assert_eq!(
dynamic_field_set,
CompositeFieldSet::TimeZone(static_field_set.into_enums()),
);
Structs§
- A builder for dynamic field sets.
Enums§
- An error that occurs when creating a field set from a builder.
- An enumeration over all possible date and calendar period field sets without options.
- An enumeration over all possible time zone styles.