1use std::error::Error;
2use std::fmt::{Display, Formatter};
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct OptionError {
6 pub code: &'static str,
7 pub message: String,
8}
9
10impl OptionError {
11 pub fn new(code: &'static str, message: impl Into<String>) -> Self {
12 Self {
13 code,
14 message: message.into(),
15 }
16 }
17}
18
19impl Display for OptionError {
20 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
21 write!(f, "{}: {}", self.code, self.message)
22 }
23}
24
25impl Error for OptionError {}
26
27pub type OptionResult<T> = Result<T, OptionError>;