Skip to main content

quo_rust/
macros.rs

1/// This macro sends the provided variable(s) or expression(s) to Quo using the `__private_quo` function.
2/// It is only active when `debug_assertions` are enabled (typically in debug builds).
3///
4/// # Examples
5///
6/// ### Sending a single variable
7/// ```rust
8/// # extern crate quo_rust as quo;
9/// use quo::quo;
10///
11/// let variable = 12;
12/// quo!(variable);
13/// ```
14///
15/// ### Sending a mutable variable
16/// To report mutability for a variable binding, use the `mut` keyword:
17/// ```rust
18/// # extern crate quo_rust as quo;
19/// use quo::quo;
20///
21/// let mut big_number = 170141183460469231731687303715884105727i128;
22/// quo!(mut big_number);
23/// ```
24///
25/// Alternatively, passing a mutable reference also works automatically:
26/// ```rust
27/// # extern crate quo_rust as quo;
28/// use quo::quo;
29///
30/// let mut big_number = 170141183460469231731687303715884105727i128;
31/// quo!(&mut big_number);
32/// ```
33///
34/// ### Sending an expression
35/// ```rust
36/// # extern crate quo_rust as quo;
37/// use quo::quo;
38///
39/// quo!(1 + 1);
40/// ```
41///
42/// ### Sending multiple arguments
43/// ```rust
44/// # extern crate quo_rust as quo;
45/// use quo::quo;
46///
47/// let variable = 43;
48/// quo!(variable, "string", 1 + 1);
49/// ```
50#[macro_export]
51macro_rules! quo {
52    ($( mut $var:ident ), + $(,)?) => {{
53        #[cfg(debug_assertions)]
54        $(
55            let quo_package_name = option_env!("CARGO_PKG_NAME").unwrap_or("Rust project"); // Make sure we don't just get `quo-rust`.
56
57            #[cfg(target_family = "wasm")]
58            {
59                let quo_file_path = concat!(env!("CARGO_MANIFEST_DIR"), "/", file!());
60                $crate::__private_quo(&$var, stringify!($var), line!(), &quo_file_path, true, false, quo_package_name);
61            }
62
63            #[cfg(not(target_family = "wasm"))]
64            {
65                let quo_path_buf = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(file!());
66                let quo_file_path = quo_path_buf.to_str().unwrap_or(file!());
67                $crate::__private_quo(&$var, stringify!($var), line!(), quo_file_path, true, false, quo_package_name);
68            }
69        )*
70    }};
71
72    ($( $var:ident ), + $(,)?) => {
73        #[cfg(debug_assertions)]
74        $(
75            {
76                let __quo_package_name = option_env!("CARGO_PKG_NAME").unwrap_or("Rust project"); // Make sure we don't just get `quo-rust`.
77
78                #[cfg(target_family = "wasm")]
79                {
80                    let quo_file_path = concat!(env!("CARGO_MANIFEST_DIR"), "/", file!());
81                    $crate::__private_quo(&$var, stringify!($var), line!(), &quo_file_path.to_owned(), false, false, __quo_package_name);
82                }
83
84                #[cfg(not(target_family = "wasm"))]
85                {
86                    let quo_path_buf = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(file!());
87                    let quo_file_path = quo_path_buf.to_str().unwrap_or(file!());
88                    $crate::__private_quo(&$var, stringify!($var), line!(), quo_file_path, false, false, __quo_package_name);
89                }
90            }
91        )*
92    };
93
94    ($( $var:expr ), + $(,)?) => {
95        #[cfg(debug_assertions)]
96        $(
97            {
98                let __quo_package_name = option_env!("CARGO_PKG_NAME").unwrap_or("Rust project"); // Make sure we don't just get `quo-rust`.
99
100                #[cfg(target_family = "wasm")]
101                {
102                    let quo_file_path = concat!(env!("CARGO_MANIFEST_DIR"), "/", file!());
103                    $crate::__private_quo(&$var, stringify!($var), line!(), &quo_file_path.to_owned(), false, true, __quo_package_name);
104                }
105
106                #[cfg(not(target_family = "wasm"))]
107                {
108                    let quo_path_buf = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(file!());
109                    let quo_file_path = quo_path_buf.to_str().unwrap_or(file!());
110                    $crate::__private_quo(&$var, stringify!($var), line!(), quo_file_path, false, true, __quo_package_name);
111                }
112            }
113        )*
114    };
115}