pef/
errors.rs

1use std::fmt::{Display, Formatter, Debug};
2
3pub enum ErrorKind {
4    UnsortedIds,
5    NoIds,
6    InvalidSourceData(usize)
7}
8
9pub struct Error {
10    error: ErrorKind,
11}
12
13impl Error {
14    pub fn unsorted_ids() -> Self {
15        Self { error: ErrorKind::UnsortedIds }
16    }
17
18    pub fn no_ids() -> Self {
19        Self { error: ErrorKind::NoIds }
20    }
21
22    pub fn invalid_bits_data(l: usize) -> Self {
23        Self { error: ErrorKind::InvalidSourceData(l) }
24    }
25}
26
27impl Display for Error {
28    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
29        match self.error {
30            ErrorKind::UnsortedIds => write!(f, "Unsorted ids cannot be compressed. Please sort."),
31            ErrorKind::NoIds => write!(f, "Emptys ids cannot be compressed."),
32            ErrorKind::InvalidSourceData(l) => write!(f, "Input data for Bits is not correct. length={}", l)
33        }
34    }
35}
36
37
38impl Debug for Error {
39    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
40        Display::fmt(&self, f)
41    }
42}
43
44impl std::error::Error for Error {}