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").unwrap()
27 }
28}
29
30impl Example for DateTime<Utc> {
31 fn example() -> Self {
32 Utc.timestamp_opt(1640988000, 0).unwrap()
33 }
34}
35
36impl Example for NaiveDate {
37 fn example() -> Self {
38 NaiveDate::from_ymd_opt(2022, 1, 1).unwrap()
39 }
40}
41
42impl Example for i32 {
43 fn example() -> Self {
44 1234
45 }
46}
47
48impl Example for u32 {
49 fn example() -> Self {
50 1234
51 }
52}
53
54impl Example for u64 {
55 fn example() -> Self {
56 1234
57 }
58}
59
60impl Example for i64 {
61 fn example() -> Self {
62 1234
63 }
64}
65
66impl Example for f32 {
67 fn example() -> Self {
68 12.34
69 }
70}
71
72impl Example for f64 {
73 fn example() -> Self {
74 12.34
75 }
76}
77
78impl Example for String {
79 fn example() -> Self {
80 "Sample string".to_string()
81 }
82}
83
84impl Example for bool {
85 fn example() -> Self {
86 false
87 }
88}