scsys_time/traits/
raw_timestamp.rs

1/*
2    appellation: timestamp <module>
3    authors: @FL03
4*/
5
6/// A marker trait indicating types capable of representing a raw timestamp value.
7pub trait RawTimestamp {
8    private!();
9}
10/// The [`TimestampRepr`] trait provides a way of associating a raw timestamp type with its
11/// corresponding value type.
12pub trait TimestampRepr {
13    type Value;
14
15    private! {}
16}
17
18/*
19 ************* Implementations *************
20*/
21use crate::timestamp::Timestamp;
22
23impl<T> TimestampRepr for Timestamp<T>
24where
25    T: RawTimestamp,
26{
27    type Value = T;
28
29    seal!();
30}
31
32impl<T> RawTimestamp for &T
33where
34    T: RawTimestamp + ?Sized,
35{
36    seal!();
37}
38
39impl<T> RawTimestamp for &mut T
40where
41    T: RawTimestamp + ?Sized,
42{
43    seal!();
44}
45
46macro_rules! impl_raw_timestamp {
47    ($($t:ty),* $(,)?) => {
48        $(
49            impl_raw_timestamp!(@impl $t);
50        )*
51    };
52    (@impl $T:ty) => {
53        impl RawTimestamp for $T {
54            seal!();
55        }
56    };
57}
58
59impl_raw_timestamp! {
60    u64,
61    u128,
62    i64,
63}
64
65impl RawTimestamp for str {
66    seal!();
67}
68
69#[cfg(feature = "alloc")]
70mod impl_alloc {
71    use super::RawTimestamp;
72    use alloc::string::String;
73
74    impl RawTimestamp for String {
75        seal!();
76    }
77}
78
79#[cfg(feature = "chrono")]
80mod impl_chrono {
81    use super::RawTimestamp;
82    use chrono::DateTime;
83    use chrono::offset::TimeZone;
84
85    impl<Tz> RawTimestamp for DateTime<Tz>
86    where
87        Tz: TimeZone,
88    {
89        seal!();
90    }
91}