#[non_exhaustive]pub struct DateFromFieldsOptions {
pub overflow: Option<Overflow>,
pub missing_fields_strategy: Option<MissingFieldsStrategy>,
}Expand description
Options bag for Date::try_from_fields.
๐ง This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
including in SemVer minor releases. Do not use this type unless you are prepared for things to occasionally break.
Graduation tracking issue: issue #7161.
โจ Enabled with the unstable Cargo feature.
Fields (Non-exhaustive)ยง
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.overflow: Option<Overflow>How to behave with out-of-bounds fields.
Defaults to Overflow::Reject.
ยงExamples
use icu::calendar::options::DateFromFieldsOptions;
use icu::calendar::options::Overflow;
use icu::calendar::types::DateFields;
use icu::calendar::Date;
use icu::calendar::Iso;
// There is no day 31 in September.
let mut fields = DateFields::default();
fields.extended_year = Some(2025);
fields.ordinal_month = Some(9);
fields.day = Some(31);
let options_default = DateFromFieldsOptions::default();
assert!(Date::try_from_fields(fields, options_default, Iso).is_err());
let mut options_reject = options_default;
options_reject.overflow = Some(Overflow::Reject);
assert!(Date::try_from_fields(fields, options_reject, Iso).is_err());
let mut options_constrain = options_default;
options_constrain.overflow = Some(Overflow::Constrain);
assert_eq!(
Date::try_from_fields(fields, options_constrain, Iso).unwrap(),
Date::try_new_iso(2025, 9, 30).unwrap()
);missing_fields_strategy: Option<MissingFieldsStrategy>How to behave when the fields that are present do not fully constitute a Date.
This option can be used to fill in a missing year given a month and a day according to the ECMAScript Temporal specification.
ยงExamples
use icu::calendar::options::DateFromFieldsOptions;
use icu::calendar::options::MissingFieldsStrategy;
use icu::calendar::types::DateFields;
use icu::calendar::Date;
use icu::calendar::Iso;
// These options are missing a year.
let mut fields = DateFields::default();
fields.month_code = Some(b"M02");
fields.day = Some(1);
let options_default = DateFromFieldsOptions::default();
assert!(Date::try_from_fields(fields, options_default, Iso).is_err());
let mut options_reject = options_default;
options_reject.missing_fields_strategy =
Some(MissingFieldsStrategy::Reject);
assert!(Date::try_from_fields(fields, options_reject, Iso).is_err());
let mut options_ecma = options_default;
options_ecma.missing_fields_strategy = Some(MissingFieldsStrategy::Ecma);
assert_eq!(
Date::try_from_fields(fields, options_ecma, Iso).unwrap(),
Date::try_new_iso(1972, 2, 1).unwrap()
);Implementationsยง
Sourceยงimpl DateFromFieldsOptions
impl DateFromFieldsOptions
pub(crate) fn from_add_options(options: DateAddOptions) -> Self
Trait Implementationsยง
Sourceยงimpl Clone for DateFromFieldsOptions
impl Clone for DateFromFieldsOptions
Sourceยงfn clone(&self) -> DateFromFieldsOptions
fn clone(&self) -> DateFromFieldsOptions
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSourceยงimpl Debug for DateFromFieldsOptions
impl Debug for DateFromFieldsOptions
Sourceยงimpl Default for DateFromFieldsOptions
impl Default for DateFromFieldsOptions
Sourceยงfn default() -> DateFromFieldsOptions
fn default() -> DateFromFieldsOptions
Returns the โdefault valueโ for a type. Read more
Sourceยงimpl PartialEq for DateFromFieldsOptions
impl PartialEq for DateFromFieldsOptions
Sourceยงfn eq(&self, other: &DateFromFieldsOptions) -> bool
fn eq(&self, other: &DateFromFieldsOptions) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Copy for DateFromFieldsOptions
impl StructuralPartialEq for DateFromFieldsOptions
Auto Trait Implementationsยง
impl Freeze for DateFromFieldsOptions
impl RefUnwindSafe for DateFromFieldsOptions
impl Send for DateFromFieldsOptions
impl Sync for DateFromFieldsOptions
impl Unpin for DateFromFieldsOptions
impl UnsafeUnpin for DateFromFieldsOptions
impl UnwindSafe for DateFromFieldsOptions
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more