#[non_exhaustive]pub enum DateDurationParseError {
InvalidStructure,
TimeNotSupported,
MissingValue,
DuplicateUnit,
NumberOverflow,
PlusNotAllowed,
}Expand description
Errors that can occur when parsing an ISO 8601 date-only duration string.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
InvalidStructure
The input does not follow the expected ISO 8601 date only duration structure.
This error occurs when the duration string is incomplete, or contains unexpected characters.
§Examples
use icu::calendar::error::DateDurationParseError;
use icu::calendar::types::DateDuration;
assert_eq!(
DateDuration::try_from_str("P"),
Err(DateDurationParseError::InvalidStructure)
);
assert_eq!(
DateDuration::try_from_str("P1"),
Err(DateDurationParseError::InvalidStructure)
);TimeNotSupported
The duration contains a time component, which is not supported.
Only date based units (Y, M, W, D) are supported. Any duration
containing a T time separator is rejected.
§Examples
use icu::calendar::error::DateDurationParseError;
use icu::calendar::types::DateDuration;
assert_eq!(
DateDuration::try_from_str("PT5M"),
Err(DateDurationParseError::TimeNotSupported)
);
assert_eq!(
DateDuration::try_from_str("P1DT"),
Err(DateDurationParseError::TimeNotSupported)
);MissingValue
A duration unit appeared without a number before it.
For example, the string contains Y, M, W, or D without a
numeric value directly in front of it.
§Examples
use icu::calendar::error::DateDurationParseError;
use icu::calendar::types::DateDuration;
assert_eq!(
DateDuration::try_from_str("PY"),
Err(DateDurationParseError::MissingValue)
);
assert_eq!(
DateDuration::try_from_str("PX1D"),
Err(DateDurationParseError::MissingValue)
);DuplicateUnit
A duration unit was specified more than once.
Each unit (Y, M, W, D) may appear at most once only.
§Examples
use icu::calendar::error::DateDurationParseError;
use icu::calendar::types::DateDuration;
assert_eq!(
DateDuration::try_from_str("P1Y2Y"),
Err(DateDurationParseError::DuplicateUnit)
);
assert_eq!(
DateDuration::try_from_str("P1D1D"),
Err(DateDurationParseError::DuplicateUnit)
);NumberOverflow
A numeric value exceeded or was more than the supported range.
§Examples
use icu::calendar::error::DateDurationParseError;
use icu::calendar::types::DateDuration;
assert_eq!(
DateDuration::try_from_str("P4294967296Y"),
Err(DateDurationParseError::NumberOverflow)
);PlusNotAllowed
A duration starts with a + sign, which is not allowed.
Only negative durations using a leading - are supported.
§Examples
use icu::calendar::error::DateDurationParseError;
use icu::calendar::types::DateDuration;
assert_eq!(
DateDuration::try_from_str("+P1D"),
Err(DateDurationParseError::PlusNotAllowed)
);Trait Implementations§
Source§impl Clone for DateDurationParseError
impl Clone for DateDurationParseError
Source§fn clone(&self) -> DateDurationParseError
fn clone(&self) -> DateDurationParseError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for DateDurationParseError
Source§impl Debug for DateDurationParseError
impl Debug for DateDurationParseError
impl Eq for DateDurationParseError
Source§impl PartialEq for DateDurationParseError
impl PartialEq for DateDurationParseError
impl StructuralPartialEq for DateDurationParseError
Auto Trait Implementations§
impl Freeze for DateDurationParseError
impl RefUnwindSafe for DateDurationParseError
impl Send for DateDurationParseError
impl Sync for DateDurationParseError
impl Unpin for DateDurationParseError
impl UnsafeUnpin for DateDurationParseError
impl UnwindSafe for DateDurationParseError
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more