bzip2_rs/decoder/
error.rs1use std::error::Error as StdError;
2use std::fmt::{self, Display, Formatter};
3use std::io;
4
5use crate::block::BlockError;
6use crate::header::HeaderError;
7
8#[derive(Debug, Clone, PartialEq)]
13pub enum DecoderError {
14 Header(HeaderError),
16 Block(BlockError),
18}
19
20impl Display for DecoderError {
21 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
22 match self {
23 DecoderError::Header(err) => write!(f, "header: {}", err),
24 DecoderError::Block(err) => write!(f, "block: {}", err),
25 }
26 }
27}
28
29impl From<HeaderError> for DecoderError {
30 fn from(err: HeaderError) -> Self {
31 DecoderError::Header(err)
32 }
33}
34
35impl From<BlockError> for DecoderError {
36 fn from(err: BlockError) -> Self {
37 DecoderError::Block(err)
38 }
39}
40
41impl StdError for DecoderError {}
42
43impl From<DecoderError> for io::Error {
44 fn from(err: DecoderError) -> io::Error {
45 match err {
46 DecoderError::Header(err) => err.into(),
47 DecoderError::Block(err) => err.into(),
48 }
49 }
50}