} else if nanos >= MAX_NANOS_F64 {
Err(FromSecsError { kind: FromSecsErrorKind::Overflow })
} else if nanos < 0.0 {
- Err(FromSecsError { kind: FromSecsErrorKind::Underflow })
+ Err(FromSecsError { kind: FromSecsErrorKind::Negative })
} else {
let nanos = nanos as u128;
Ok(Duration {
} else if nanos >= MAX_NANOS_F32 {
Err(FromSecsError { kind: FromSecsErrorKind::Overflow })
} else if nanos < 0.0 {
- Err(FromSecsError { kind: FromSecsErrorKind::Underflow })
+ Err(FromSecsError { kind: FromSecsErrorKind::Negative })
} else {
let nanos = nanos as u128;
Ok(Duration {
impl FromSecsError {
const fn description(&self) -> &'static str {
match self.kind {
- FromSecsErrorKind::NonFinite => {
- "got non-finite value when converting float to duration"
- }
+ FromSecsErrorKind::NonFinite => "non-finite value when converting float to duration",
FromSecsErrorKind::Overflow => "overflow when converting float to duration",
- FromSecsErrorKind::Underflow => "underflow when converting float to duration",
+ FromSecsErrorKind::Negative => "negative value when converting float to duration",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
enum FromSecsErrorKind {
- // Value is not a finite value (either infinity or NaN).
+ // Value is not a finite value (either + or - infinity or NaN).
NonFinite,
// Value is too large to store in a `Duration`.
Overflow,
- // Value is less than `0.0`.
- Underflow,
+ // Value is negative.
+ Negative,
}