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 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 f.write_str(data:"Source value is out of range for the target type")
15 }
16}
17
18#[cfg(feature = "std")]
19impl std::error::Error for ConversionRange {}
20
21impl From<ConversionRange> for crate::Error {
22 fn from(err: ConversionRange) -> Self {
23 Self::ConversionRange(err)
24 }
25}
26
27impl TryFrom<crate::Error> for ConversionRange {
28 type Error = error::DifferentVariant;
29
30 fn try_from(err: crate::Error) -> Result<Self, Self::Error> {
31 match err {
32 crate::Error::ConversionRange(err: ConversionRange) => Ok(err),
33 _ => Err(error::DifferentVariant),
34 }
35 }
36}
37