1use chrono::NaiveDateTime;
4
5use crate::cargo::Profile;
6use crate::rust::Channel;
7
8#[allow(clippy::module_name_repetitions)]
25#[macro_export]
26macro_rules! build_info {
27 () => {{
28 macro_rules! build {
29 () => {{
30 let datetime = {
31 let datetime = env!("CHKSUM_BUILD_INFO_BUILD_DATETIME");
32 ::chrono::NaiveDateTime::parse_from_str(&datetime, "%Y-%m-%d %H:%M:%S")?
33 };
34
35 ::chksum_build::Build::new(datetime)
36 }};
37 }
38
39 macro_rules! cargo {
40 () => {{
41 let profile = {
42 use ::std::str::FromStr;
43
44 let profile = env!("CHKSUM_BUILD_INFO_CARGO_PROFILE");
45 ::chksum_build::cargo::Profile::from_str(profile)?
46 };
47
48 ::chksum_build::Cargo::new(profile)
49 }};
50 }
51
52 macro_rules! rust {
53 () => {{
54 let channel = {
55 use ::std::str::FromStr;
56
57 let channel = env!("CHKSUM_BUILD_INFO_RUST_CHANNEL");
58 ::chksum_build::rust::Channel::from_str(channel)?
59 };
60
61 ::chksum_build::Rust::new(channel)
62 }};
63 }
64
65 let build = build!();
66 let cargo = cargo!();
67 let rust = rust!();
68
69 ::chksum_build::BuildInfo::new(build, cargo, rust)
70 }};
71}
72
73#[derive(Debug, Eq, PartialEq)]
75pub struct Build {
76 datetime: NaiveDateTime,
77}
78
79impl Build {
80 #[cfg_attr(docsrs, doc(hidden))]
81 #[inline]
82 #[must_use]
83 pub const fn new(datetime: NaiveDateTime) -> Self {
84 Self { datetime }
85 }
86
87 #[inline]
89 #[must_use]
90 pub const fn datetime(&self) -> &NaiveDateTime {
91 &self.datetime
92 }
93}
94
95#[derive(Debug, Eq, PartialEq)]
97pub struct Cargo {
98 profile: Profile,
99}
100
101impl Cargo {
102 #[cfg_attr(docsrs, doc(hidden))]
103 #[inline]
104 #[must_use]
105 pub const fn new(profile: Profile) -> Self {
106 Self { profile }
107 }
108
109 #[inline]
113 #[must_use]
114 pub const fn profile(&self) -> &Profile {
115 &self.profile
116 }
117}
118
119#[derive(Debug, Eq, PartialEq)]
121pub struct Rust {
122 channel: Channel,
123}
124
125impl Rust {
126 #[cfg_attr(docsrs, doc(hidden))]
127 #[inline]
128 #[must_use]
129 pub const fn new(channel: Channel) -> Self {
130 Self { channel }
131 }
132
133 #[inline]
137 #[must_use]
138 pub const fn channel(&self) -> &Channel {
139 &self.channel
140 }
141}
142
143#[allow(clippy::module_name_repetitions)]
145#[derive(Debug, Eq, PartialEq)]
146pub struct BuildInfo {
147 build: Build,
148 cargo: Cargo,
149 rust: Rust,
150}
151
152impl BuildInfo {
153 #[cfg_attr(docsrs, doc(hidden))]
154 #[inline]
155 #[must_use]
156 pub const fn new(build: Build, cargo: Cargo, rust: Rust) -> Self {
157 Self { build, cargo, rust }
158 }
159
160 #[inline]
162 #[must_use]
163 pub const fn build(&self) -> &Build {
164 &self.build
165 }
166
167 #[inline]
169 #[must_use]
170 pub const fn cargo(&self) -> &Cargo {
171 &self.cargo
172 }
173
174 #[inline]
176 #[must_use]
177 pub const fn rust(&self) -> &Rust {
178 &self.rust
179 }
180}