1use std::{error::Error, fmt, str};
2
3#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
5pub enum ParseIntErr {
6 InvalidDigit([u8; 1]),
8
9 Overflow,
11}
12
13impl fmt::Display for ParseIntErr {
14 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
15 match *self {
16 ParseIntErr::InvalidDigit([ref c]) => write!(f, "ParseIntErr::InvalidDigit({})", c),
17 ParseIntErr::Overflow => f.pad("ParseIntErr::Overflow"),
18 }
19 }
20}
21
22impl Error for ParseIntErr {
23 fn description(&self) -> &str {
24 match *self {
25 ParseIntErr::InvalidDigit(ref c) => str::from_utf8(c).unwrap(),
26 ParseIntErr::Overflow => "number too large to fit in the target type",
27 }
28 }
29}
30
31impl ParseIntErr {
32 pub fn with_byte(c: u8) -> Self {
33 ParseIntErr::InvalidDigit([c])
34 }
35}