headless_lms_server/programs/doc_file_generator/
example.rs1use chrono::{DateTime, NaiveDate, TimeZone, Utc};
2use uuid::Uuid;
3
4pub trait Example {
5 fn example() -> Self;
6}
7
8impl Example for () {
9 fn example() -> Self {}
10}
11
12impl<T: Example> Example for Option<T> {
13 fn example() -> Self {
14 Some(T::example())
15 }
16}
17
18impl<T: Example> Example for Vec<T> {
19 fn example() -> Self {
20 vec![T::example()]
21 }
22}
23
24impl Example for Uuid {
25 fn example() -> Self {
26 Uuid::parse_str("307fa56f-9853-4f5c-afb9-a6736c232f32")
27 .expect("Invalid UUID constant in Example implementation")
28 }
29}
30
31impl Example for DateTime<Utc> {
32 fn example() -> Self {
33 Utc.timestamp_opt(1640988000, 0).unwrap()
34 }
35}
36
37impl Example for NaiveDate {
38 fn example() -> Self {
39 NaiveDate::from_ymd_opt(2022, 1, 1)
40 .expect("Invalid date constant in Example implementation")
41 }
42}
43
44impl Example for i32 {
45 fn example() -> Self {
46 1234
47 }
48}
49
50impl Example for u32 {
51 fn example() -> Self {
52 1234
53 }
54}
55
56impl Example for u64 {
57 fn example() -> Self {
58 1234
59 }
60}
61
62impl Example for i64 {
63 fn example() -> Self {
64 1234
65 }
66}
67
68impl Example for f32 {
69 fn example() -> Self {
70 12.34
71 }
72}
73
74impl Example for f64 {
75 fn example() -> Self {
76 12.34
77 }
78}
79
80impl Example for String {
81 fn example() -> Self {
82 "Sample string".to_string()
83 }
84}
85
86impl Example for bool {
87 fn example() -> Self {
88 false
89 }
90}