mantra_rust_macros/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3pub use mantra_rust_procm::req;
4pub use mantra_rust_procm::reqcov;
5
6#[cfg(feature = "extract")]
7pub mod extract;
8
9/// Type alias that must be in sync with `mantra_schema::Line`.
10/// Adding `mantra-schema` as dependency is not feasible due to `no_std` usage for this macro crate.
11type Line = u32;
12
13#[inline]
14#[allow(unused)]
15pub fn req_print(req: ReqCovStatic) {
16    #[cfg(feature = "log")]
17    log::trace!("{}", req);
18
19    #[cfg(feature = "defmt")]
20    defmt::println!("{}", req);
21
22    #[cfg(feature = "stdout")]
23    println!("{}", req);
24}
25
26#[macro_export]
27macro_rules! mr_reqcov {
28    ($($req_id:literal),+) => {
29        $(
30            $crate::req_print($crate::ReqCovStatic{id: $req_id, file: file!(), line: line!()});
31        )+
32    };
33}
34
35#[doc(hidden)]
36pub struct ReqCovStatic {
37    pub id: &'static str,
38    pub file: &'static str,
39    pub line: Line,
40}
41
42#[cfg(feature = "defmt")]
43impl defmt::Format for ReqCovStatic {
44    fn format(&self, fmt: defmt::Formatter) {
45        defmt::write!(
46            fmt,
47            "mantra: req-id=`{=str}`; file='{=str}'; line='{}';",
48            self.id,
49            self.file,
50            self.line
51        )
52    }
53}
54
55impl core::fmt::Display for ReqCovStatic {
56    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
57        write!(
58            f,
59            "mantra: req-id=`{}`; file='{}'; line='{}';",
60            self.id, self.file, self.line
61        )
62    }
63}