Skip to content

Commit c62e8b3

Browse files
committed
flatten DateFromFieldsError::Range
1 parent 80e5892 commit c62e8b3

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

components/calendar/src/error.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,21 @@ mod unstable {
143143
///
144144
/// assert!(matches!(
145145
/// err,
146-
/// DateFromFieldsError::Range(RangeError { field: "month", .. })
147-
/// ));
146+
/// DateFromFieldsError::Range { field: "month", .. })
147+
/// );
148148
/// ```
149-
#[displaydoc("{0}")]
150-
Range(RangeError),
149+
#[displaydoc("The {field} = {value} argument is out of range {min}..={max}")]
150+
#[non_exhaustive]
151+
Range {
152+
/// The field that is out of range, such as "year"
153+
field: &'static str,
154+
/// The actual value
155+
value: i32,
156+
/// The minimum value (inclusive). This might not be tight.
157+
min: i32,
158+
/// The maximum value (inclusive). This might not be tight.
159+
max: i32,
160+
},
151161
/// The era code is invalid for the calendar.
152162
#[displaydoc("Unknown era or invalid syntax")]
153163
UnknownEra,
@@ -323,7 +333,18 @@ mod unstable {
323333
impl From<RangeError> for DateFromFieldsError {
324334
#[inline]
325335
fn from(value: RangeError) -> Self {
326-
DateFromFieldsError::Range(value)
336+
let RangeError {
337+
field,
338+
value,
339+
min,
340+
max,
341+
} = value;
342+
DateFromFieldsError::Range {
343+
field,
344+
value,
345+
min,
346+
max,
347+
}
327348
}
328349
}
329350
}

ffi/capi/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl From<icu_calendar::DateError> for CalendarError {
205205
impl From<icu_calendar::error::DateFromFieldsError> for CalendarDateFromFieldsError {
206206
fn from(e: icu_calendar::error::DateFromFieldsError) -> Self {
207207
match e {
208-
icu_calendar::error::DateFromFieldsError::Range(_) => Self::OutOfRange,
208+
icu_calendar::error::DateFromFieldsError::Range { .. } => Self::OutOfRange,
209209
icu_calendar::error::DateFromFieldsError::UnknownEra => Self::UnknownEra,
210210
icu_calendar::error::DateFromFieldsError::MonthCodeInvalidSyntax => {
211211
Self::MonthCodeInvalidSyntax

0 commit comments

Comments
 (0)