Skip to main content

alpaca_time/
error.rs

1use std::error::Error;
2use std::fmt::{Display, Formatter};
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct TimeError {
6    pub code: &'static str,
7    pub message: String,
8}
9
10impl TimeError {
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 TimeError {
20    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
21        write!(f, "{}: {}", self.code, self.message)
22    }
23}
24
25impl Error for TimeError {}
26
27pub type TimeResult<T> = Result<T, TimeError>;