#[non_exhaustive]pub enum DateFromFieldsError {
Range(RangeError),
UnknownEra,
MonthCodeInvalidSyntax,
MonthCodeNotInCalendar,
MonthCodeNotInYear,
InconsistentYear,
InconsistentMonth,
NotEnoughFields,
}Expand description
Error type for date creation via 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.
Variants (Non-exhaustive)ยง
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Range(RangeError)
A field is out of range for its domain.
ยงExamples
use icu::calendar::error::DateFromFieldsError;
use icu::calendar::error::RangeError;
use icu::calendar::types::DateFields;
use icu::calendar::Date;
use icu::calendar::Iso;
let mut fields = DateFields::default();
fields.extended_year = Some(2000);
fields.ordinal_month = Some(13);
fields.day = Some(1);
let err = Date::try_from_fields(fields, Default::default(), Iso)
.expect_err("no month 13 in the ISO calendar");
assert!(matches!(
err,
DateFromFieldsError::Range(RangeError { field: "month", .. })
));UnknownEra
The era code is invalid for the calendar.
MonthCodeInvalidSyntax
The month code syntax is invalid.
ยงExamples
use icu::calendar::error::DateFromFieldsError;
use icu::calendar::types::DateFields;
use icu::calendar::Date;
use icu::calendar::Iso;
let mut fields = DateFields::default();
fields.extended_year = Some(2000);
fields.month_code = Some(b"????");
fields.day = Some(1);
let err = Date::try_from_fields(fields, Default::default(), Iso)
.expect_err("month code is invalid");
assert_eq!(err, DateFromFieldsError::MonthCodeInvalidSyntax);MonthCodeNotInCalendar
The specified month code does not exist in this calendar.
ยงExamples
use icu::calendar::cal::Hebrew;
use icu::calendar::error::DateFromFieldsError;
use icu::calendar::types::DateFields;
use icu::calendar::Date;
let mut fields = DateFields::default();
fields.extended_year = Some(5783);
fields.month_code = Some(b"M13");
fields.day = Some(1);
let err = Date::try_from_fields(fields, Default::default(), Hebrew)
.expect_err("no month M13 in Hebrew");
assert_eq!(err, DateFromFieldsError::MonthCodeNotInCalendar);MonthCodeNotInYear
The specified month code exists in this calendar, but not in the specified year.
ยงExamples
use icu::calendar::cal::Hebrew;
use icu::calendar::error::DateFromFieldsError;
use icu::calendar::types::DateFields;
use icu::calendar::Date;
let mut fields = DateFields::default();
fields.extended_year = Some(5783);
fields.month_code = Some(b"M05L");
fields.day = Some(1);
let err = Date::try_from_fields(fields, Default::default(), Hebrew)
.expect_err("no month M05L in Hebrew year 5783");
assert_eq!(err, DateFromFieldsError::MonthCodeNotInYear);InconsistentYear
The year was specified in multiple inconsistent ways.
ยงExamples
use icu::calendar::cal::Japanese;
use icu::calendar::error::DateFromFieldsError;
use icu::calendar::types::DateFields;
use icu::calendar::Date;
let mut fields = DateFields::default();
fields.era = Some(b"reiwa");
fields.era_year = Some(6);
fields.ordinal_month = Some(1);
fields.day = Some(1);
Date::try_from_fields(fields, Default::default(), Japanese::new())
.expect("a well-defined Japanese date");
fields.extended_year = Some(1900);
let err =
Date::try_from_fields(fields, Default::default(), Japanese::new())
.expect_err("year 1900 is not the same as 6 Reiwa");
assert_eq!(err, DateFromFieldsError::InconsistentYear);InconsistentMonth
The month was specified in multiple inconsistent ways.
ยงExamples
use icu::calendar::cal::Hebrew;
use icu::calendar::error::DateFromFieldsError;
use icu::calendar::types::DateFields;
use icu::calendar::Date;
use tinystr::tinystr;
let mut fields = DateFields::default();
fields.extended_year = Some(5783);
fields.month_code = Some(b"M06");
fields.ordinal_month = Some(6);
fields.day = Some(1);
Date::try_from_fields(fields, Default::default(), Hebrew)
.expect("a well-defined Hebrew date in a common year");
fields.extended_year = Some(5784);
let err = Date::try_from_fields(fields, Default::default(), Hebrew)
.expect_err("month M06 is not the 6th month in leap year 5784");
assert_eq!(err, DateFromFieldsError::InconsistentMonth);NotEnoughFields
Not enough fields were specified to form a well-defined date.
ยงExamples
use icu::calendar::cal::Hebrew;
use icu::calendar::error::DateFromFieldsError;
use icu::calendar::types::DateFields;
use icu::calendar::Date;
use tinystr::tinystr;
let mut fields = DateFields::default();
fields.ordinal_month = Some(3);
let err = Date::try_from_fields(fields, Default::default(), Hebrew)
.expect_err("need more than just an ordinal month");
assert_eq!(err, DateFromFieldsError::NotEnoughFields);
fields.era_year = Some(5783);
let err = Date::try_from_fields(fields, Default::default(), Hebrew)
.expect_err("need more than an ordinal month and an era year");
assert_eq!(err, DateFromFieldsError::NotEnoughFields);
fields.extended_year = Some(5783);
let err = Date::try_from_fields(fields, Default::default(), Hebrew)
.expect_err("era year still needs an era");
assert_eq!(err, DateFromFieldsError::NotEnoughFields);
fields.era = Some(b"am");
let date = Date::try_from_fields(fields, Default::default(), Hebrew)
.expect_err("still missing the day");
assert_eq!(err, DateFromFieldsError::NotEnoughFields);
fields.day = Some(1);
let date = Date::try_from_fields(fields, Default::default(), Hebrew)
.expect("we have enough fields!");Trait Implementationsยง
Sourceยงimpl Clone for DateFromFieldsError
impl Clone for DateFromFieldsError
Sourceยงfn clone(&self) -> DateFromFieldsError
fn clone(&self) -> DateFromFieldsError
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 DateFromFieldsError
impl Debug for DateFromFieldsError
Sourceยงimpl Display for DateFromFieldsError
impl Display for DateFromFieldsError
Sourceยงimpl Error for DateFromFieldsError
impl Error for DateFromFieldsError
1.30.0 ยท Sourceยงfn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 ยท Sourceยงfn description(&self) -> &str
fn description(&self) -> &str
๐Deprecated since 1.42.0:
use the Display impl or to_string()
Sourceยงimpl From<EcmaReferenceYearError> for DateFromFieldsError
impl From<EcmaReferenceYearError> for DateFromFieldsError
Sourceยงfn from(value: EcmaReferenceYearError) -> Self
fn from(value: EcmaReferenceYearError) -> Self
Converts to this type from the input type.
Sourceยงimpl From<MonthCodeError> for DateFromFieldsError
impl From<MonthCodeError> for DateFromFieldsError
Sourceยงfn from(value: MonthCodeError) -> Self
fn from(value: MonthCodeError) -> Self
Converts to this type from the input type.
Sourceยงimpl From<MonthCodeParseError> for DateFromFieldsError
impl From<MonthCodeParseError> for DateFromFieldsError
Sourceยงfn from(value: MonthCodeParseError) -> Self
fn from(value: MonthCodeParseError) -> Self
Converts to this type from the input type.
Sourceยงimpl From<RangeError> for DateFromFieldsError
impl From<RangeError> for DateFromFieldsError
Sourceยงfn from(value: RangeError) -> Self
fn from(value: RangeError) -> Self
Converts to this type from the input type.
Sourceยงimpl From<UnknownEraError> for DateFromFieldsError
impl From<UnknownEraError> for DateFromFieldsError
Sourceยงfn from(_value: UnknownEraError) -> Self
fn from(_value: UnknownEraError) -> Self
Converts to this type from the input type.
Sourceยงimpl PartialEq for DateFromFieldsError
impl PartialEq for DateFromFieldsError
Sourceยงfn eq(&self, other: &DateFromFieldsError) -> bool
fn eq(&self, other: &DateFromFieldsError) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Copy for DateFromFieldsError
impl StructuralPartialEq for DateFromFieldsError
Auto Trait Implementationsยง
impl Freeze for DateFromFieldsError
impl RefUnwindSafe for DateFromFieldsError
impl Send for DateFromFieldsError
impl Sync for DateFromFieldsError
impl Unpin for DateFromFieldsError
impl UnsafeUnpin for DateFromFieldsError
impl UnwindSafe for DateFromFieldsError
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