Skip to main content

bzip2_rs/block/
error.rs

1use std::error::Error as StdError;
2use std::fmt::{self, Display, Formatter};
3use std::io;
4
5/// An error returned by the block decoder
6///
7/// At the moment it's not possible to find out what
8/// error occurred other than through the `Display`
9/// implementation, this will change in a future release.
10#[derive(Debug, Clone, PartialEq)]
11pub struct BlockError {
12    reason: &'static str,
13}
14
15impl BlockError {
16    #[inline(always)]
17    pub(super) fn new(reason: &'static str) -> Self {
18        Self { reason }
19    }
20}
21
22impl Display for BlockError {
23    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
24        f.write_str(self.reason)
25    }
26}
27
28impl StdError for BlockError {}
29
30impl From<BlockError> for io::Error {
31    fn from(err: BlockError) -> io::Error {
32        // TODO: do better at this
33        io::Error::new(io::ErrorKind::Other, err)
34    }
35}