time/error/
conversion_range.rs

1//! Conversion range error
2
3use core::fmt;
4
5use crate::error;
6
7/// An error type indicating that a conversion failed because the target type could not store the
8/// initial value.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub struct ConversionRange;
11
12impl fmt::Display for ConversionRange {
13    #[inline]
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        f.write_str("Source value is out of range for the target type")
16    }
17}
18
19impl core::error::Error for ConversionRange {}
20
21impl From<ConversionRange> for crate::Error {
22    #[inline]
23    fn from(err: ConversionRange) -> Self {
24        Self::ConversionRange(err)
25    }
26}
27
28impl TryFrom<crate::Error> for ConversionRange {
29    type Error = error::DifferentVariant;
30
31    #[inline]
32    fn try_from(err: crate::Error) -> Result<Self, Self::Error> {
33        match err {
34            crate::Error::ConversionRange(err) => Ok(err),
35            _ => Err(error::DifferentVariant),
36        }
37    }
38}