| 1 |
use std::error::Error as StdError; |
| 2 |
use std::fmt::{self, Display, Formatter}; |
| 3 |
use 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)] |
| 11 |
pub struct BlockError { |
| 12 |
reason: &'static str, |
| 13 |
} |
| 14 |
|
| 15 |
impl BlockError { |
| 16 |
#[inline(always)] |
| 17 |
pub(super) fn new(reason: &'static str) -> Self { |
| 18 |
Self { reason } |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
impl Display for BlockError { |
| 23 |
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 24 |
f.write_str(self.reason) |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
impl StdError for BlockError {} |
| 29 |
|
| 30 |
impl 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 |
} |