holochain_timestamp/
error.rs1#[cfg(feature = "now")]
2use chrono::ParseError;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum TimestampError {
6 Overflow,
7 #[cfg(feature = "now")]
8 ParseError(ParseError),
9 OutOfOrder,
10}
11
12pub type TimestampResult<T> = Result<T, TimestampError>;
13
14impl std::error::Error for TimestampError {
15 #[cfg(feature = "now")]
16 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
17 match self {
18 TimestampError::Overflow => None,
19 TimestampError::ParseError(e) => e.source(),
20 TimestampError::OutOfOrder => None,
21 }
22 }
23}
24
25#[cfg(feature = "now")]
26impl From<ParseError> for TimestampError {
27 fn from(e: ParseError) -> Self {
28 Self::ParseError(e)
29 }
30}
31
32impl core::fmt::Display for TimestampError {
33 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 match self {
35 TimestampError::Overflow => write!(
36 f,
37 "Overflow in adding, subtracting or creating from a Duration."
38 ),
39 #[cfg(feature = "now")]
40 TimestampError::ParseError(s) => s.fmt(f),
41 TimestampError::OutOfOrder => {
42 write!(f, "Start was after the end of a Timestamp bounded range.")
43 }
44 }
45 }
46}