1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use core::{
fmt::{self, Debug, Display, Formatter},
num::ParseIntError as StdParseIntError,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseIntError {
pub(crate) kind: ParseIntErrorKind,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) enum ParseIntErrorKind {
Overflow,
Underflow,
Unknown(StdParseIntError),
}
impl From<StdParseIntError> for ParseIntError {
fn from(e: StdParseIntError) -> Self {
ParseIntError { kind: ParseIntErrorKind::Unknown(e) }
}
}
impl Display for ParseIntError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match &self.kind {
ParseIntErrorKind::Overflow => f.write_str("number too large to fit in target type"),
ParseIntErrorKind::Underflow => f.write_str("number too small to fit in target type"),
ParseIntErrorKind::Unknown(e) => write!(f, "{}", e),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for ParseIntError {}
#[derive(Clone)]
pub struct TryFromIntError {
_private: (),
}
impl TryFromIntError {
pub(crate) fn new() -> Self {
Self { _private: () }
}
}
impl Display for TryFromIntError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.write_str("out of range integral type conversion attempted")
}
}
impl Debug for TryFromIntError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.write_str("TryFromIntError")
}
}
#[cfg(feature = "std")]
impl std::error::Error for TryFromIntError {}