1use std::error::Error;
2use std::fmt;
3
4pub type Result<T> = std::result::Result<T, ModelIoError>;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct ModelIoError {
10 code: i32,
11 message: String,
12}
13
14impl ModelIoError {
15 pub(crate) fn new(code: i32, message: impl Into<String>) -> Self {
17 Self {
18 code,
19 message: message.into(),
20 }
21 }
22
23 #[must_use]
24 pub fn code(&self) -> i32 {
26 self.code
27 }
28
29 #[must_use]
30 pub fn message(&self) -> &str {
32 &self.message
33 }
34}
35
36impl fmt::Display for ModelIoError {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 write!(f, "{} (status {})", self.message, self.code)
39 }
40}
41
42impl Error for ModelIoError {}