Skip to main content

DateFromFieldsOptions

Struct DateFromFieldsOptions 

Source
#[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ยง

Trait Implementationsยง

Sourceยง

impl Clone for DateFromFieldsOptions

Sourceยง

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)

Performs copy-assignment from source. Read more
Sourceยง

impl Copy for DateFromFieldsOptions

Sourceยง

impl Debug for DateFromFieldsOptions

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl Default for DateFromFieldsOptions

Sourceยง

fn default() -> DateFromFieldsOptions

Returns the โ€œdefault valueโ€ for a type. Read more
Sourceยง

impl PartialEq for DateFromFieldsOptions

Sourceยง

fn eq(&self, other: &DateFromFieldsOptions) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) ยท Sourceยง

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Sourceยง

impl StructuralPartialEq for DateFromFieldsOptions

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> CloneToUninit for T
where T: Clone,

Sourceยง

unsafe fn clone_to_uninit(&self, dest: *mut u8)

๐Ÿ”ฌThis is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Sourceยง

impl<T> ErasedDestructor for T
where T: 'static,

Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T> ToOwned for T
where T: Clone,

Sourceยง

type Owned = T

The resulting type after obtaining ownership.
Sourceยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Sourceยง

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.