1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#[cfg(feature = "std")]
use std::io;
#[cfg(not(feature = "std"))]
use alloc::string::String;
use snafu::Snafu;
#[derive(Snafu, Debug)]
pub enum Error {
#[snafu(display("An offset of 0x{:x} is too small.", offset))]
OffsetTooSmall { offset: usize },
#[snafu(display("An offset of 0x{:x} is too large.", offset))]
OffsetTooLarge { offset: usize },
#[snafu(display("Requested {} bytes, but only {} bytes left.", requested, left))]
NotEnoughData { requested: usize, left: usize },
#[snafu(display("No more data left.",))]
NoMoreData,
#[cfg(feature = "std")]
#[snafu(display("{}", error))]
IoError { error: io::Error },
#[snafu(display("{}", message))]
Other { message: String },
}
#[cfg(feature = "std")]
impl From<Error> for io::Error {
fn from(e: Error) -> Self {
io::Error::new(io::ErrorKind::Other, e)
}
}
#[cfg(feature = "std")]
impl From<io::Error> for Error {
fn from(error: io::Error) -> Self {
Self::IoError { error }
}
}
pub type Result<V> = core::result::Result<V, Error>;