1use std::error::Error as StdError;
2use std::fmt::{self, Display, Formatter};
3
4use libraw_sys as sys;
5
6pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, Clone)]
9pub struct Error {
10 code: i32,
11}
12
13impl Error {
14 pub(crate) fn check(code: i32) -> Result<()> {
15 if code == sys::LibRaw_errors_LIBRAW_SUCCESS {
16 Ok(())
17 } else {
18 Err(Error { code })
19 }
20 }
21}
22
23impl Display for Error {
24 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
25 write!(f, "libraw error: {}", self.code)
26 }
27}
28
29impl StdError for Error {}