From e3087537d57d7c87b39af28bc9cdf3dfdd6249e3 Mon Sep 17 00:00:00 2001 From: Kart Date: Thu, 18 Jul 2024 17:52:54 +0530 Subject: [PATCH] DurationFormatter: validated_options: add documentation to DurationFormatterOptionsError (#5210) --- .../duration/formatter/validated_options.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/components/experimental/src/duration/formatter/validated_options.rs b/components/experimental/src/duration/formatter/validated_options.rs index 91ae5dcc147..c37c7923080 100644 --- a/components/experimental/src/duration/formatter/validated_options.rs +++ b/components/experimental/src/duration/formatter/validated_options.rs @@ -59,10 +59,19 @@ pub struct ValidatedDurationFormatterOptions { fractional_digits: FractionalDigits, } -/// Error type for [DurationFormatterOptions] validation. +/// Error type for [`DurationFormatterOptions`] validation. #[non_exhaustive] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum DurationFormatterOptionsError { - InvalidFractionalDigits, + /// Returned when a unit field is set to [`FieldDisplay::Always`] and the style is set to [`FieldStyle::Fractional`]. + DisplayAlwaysFractional, + + /// Returned when a previous unit's style is [`FieldStyle::Fractional`], but the following unit's style is not [`FieldStyle::Fractional`]. + PreviousFractional, + + /// Returned when a previous unit's style is set to [`FieldStyle::Numeric`] or [`FieldStyle::TwoDigit`] and the following unit's style is not + /// [`FieldStyle::Fractional`], [`FieldStyle::Numeric`], or [`FieldStyle::TwoDigit`]. + PreviousNumeric, } impl ValidatedDurationFormatterOptions { @@ -139,7 +148,7 @@ impl ValidatedDurationFormatterOptions { // 7. If display is "always" and style is "fractional", then if *visibility == Some(FieldDisplay::Always) && *style == Some(FieldStyle::Fractional) { // a. Throw a RangeError exception. - return Err(DurationFormatterOptionsError::InvalidFractionalDigits); + return Err(DurationFormatterOptionsError::DisplayAlwaysFractional); } // 8. If prevStyle is "fractional", then @@ -147,7 +156,7 @@ impl ValidatedDurationFormatterOptions { // a. If style is not "fractional", then if *style != Some(FieldStyle::Fractional) { // i. Throw a RangeError exception. - return Err(DurationFormatterOptionsError::InvalidFractionalDigits); + return Err(DurationFormatterOptionsError::PreviousFractional); } } @@ -159,7 +168,7 @@ impl ValidatedDurationFormatterOptions { Some(FieldStyle::Fractional | FieldStyle::Numeric | FieldStyle::TwoDigit) ) { // i. Throw a RangeError exception. - return Err(DurationFormatterOptionsError::InvalidFractionalDigits); + return Err(DurationFormatterOptionsError::PreviousNumeric); } // b. If unit is "minutes" or "seconds", then if unit == Unit::Minute || unit == Unit::Second {