oct/error/
system_time_decode_error.rs

1// Copyright 2024-2025 Gabriel Bjørnager Jensen.
2//
3// This Source Code Form is subject to the terms of
4// the Mozilla Public License, v. 2.0. If a copy of
5// the MPL was not distributed with this file, you
6// can obtain one at:
7// <https://mozilla.org/MPL/2.0/>.
8
9#![cfg(feature = "std")]
10
11use core::convert::Infallible;
12use core::error::Error;
13use core::fmt::{self, Display, Formatter};
14
15/// The [`SystemTime`](std::time::SystemTime) type could not represent a UNIX timestamp.
16///
17/// Note that a UNIX timestamp is here defined as a signed, 64-bit integer denoting a difference of time to 1 january 1970, as measured in Greenwich using seconds.
18/// This error should therefore not occur on systems that use the same or a more precise counter.
19#[cfg_attr(feature = "unstable-docs", doc(cfg(feature = "std")))]
20#[derive(Debug, Eq, PartialEq)]
21#[must_use]
22pub struct SystemTimeDecodeError {
23	/// The unrepresentable timestamp.
24	pub timestamp: i64,
25}
26
27#[cfg_attr(feature = "unstable-docs", doc(cfg(feature = "std")))]
28impl Display for SystemTimeDecodeError {
29	#[inline]
30	fn fmt(&self, f: &mut Formatter) -> fmt::Result {
31		write!(f, "could not represent `{}` as a system timestamp", self.timestamp)
32	}
33}
34
35#[cfg_attr(feature = "unstable-docs", doc(cfg(feature = "std")))]
36impl Error for SystemTimeDecodeError { }
37
38#[cfg_attr(feature = "unstable-docs", doc(cfg(feature = "std")))]
39impl From<Infallible> for SystemTimeDecodeError {
40	#[inline(always)]
41	fn from(_value: Infallible) -> Self {
42		unreachable!()
43	}
44}