1use rst_common::standard::chrono::Timelike;
2
3pub trait UID {
9 type Value;
10
11 fn uid(&self) -> Self::Value;
12}
13
14pub trait Timestamp {
15 type CreatedAt: Timelike;
16 type UpdatedAt: Timelike;
17
18 fn created_at(&self) -> Self::CreatedAt;
19 fn updated_at(&self) -> Self::UpdatedAt;
20}
21
22#[cfg(test)]
23mod tests {
24 use super::*;
25 use rst_common::standard::chrono::{DateTime, Utc};
26
27 struct FakeTimestamp {
28 created_at: DateTime<Utc>,
29 updated_at: DateTime<Utc>
30 }
31
32 impl Default for FakeTimestamp {
33 fn default() -> Self {
34 Self { created_at: Utc::now(), updated_at: Utc::now() }
35 }
36 }
37
38 impl Timestamp for FakeTimestamp {
39 type CreatedAt = DateTime<Utc>;
40 type UpdatedAt = DateTime<Utc>;
41
42 fn created_at(&self) -> Self::CreatedAt {
43 self.created_at
44 }
45
46 fn updated_at(&self) -> Self::UpdatedAt {
47 self.updated_at
48 }
49 }
50
51 #[test]
52 fn test_timestamp() {
53 let fts = FakeTimestamp::default();
54 assert!(!fts.created_at().to_string().is_empty());
55 assert!(!fts.updated_at().to_string().is_empty())
56 }
57}