byte_calc/
errors.rs

1//! Error types.
2
3/// Unable to parse byte unit.
4#[derive(Debug)]
5pub struct ByteUnitParseError;
6
7impl core::fmt::Display for ByteUnitParseError {
8    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
9        f.write_str("unable to parse byte unit, the provided unit is invalid")
10    }
11}
12
13impl core::error::Error for ByteUnitParseError {}
14
15/// Unable to parse number of bytes.
16#[derive(Debug)]
17pub enum NumBytesParseError {
18    Format,
19    Overflow,
20}
21
22impl core::fmt::Display for NumBytesParseError {
23    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
24        match self {
25            NumBytesParseError::Format => {
26                f.write_str("unable to parse number of bytes, invalid format")
27            }
28            NumBytesParseError::Overflow => {
29                f.write_str("unable to parse number of bytes, number does not fit into `u64`")
30            }
31        }
32    }
33}
34
35impl core::error::Error for NumBytesParseError {}