1 /// Asserts that a given configuration is set.
2 ///
3 /// # Examples
4 ///
5 /// A project will simply fail to compile if the given configuration is not set.
6 ///
7 /// ```
8 /// # #[macro_use] extern crate static_assertions;
9 /// # fn main() {}
10 /// // We're not masochists
11 /// # #[cfg(not(target_pointer_width = "16"))] // Just in case
12 /// assert_cfg!(not(target_pointer_width = "16"));
13 /// ```
14 ///
15 /// If a project does not support a set of configurations, you may want to
16 /// report why. There is the option of providing a compile error message string:
17 ///
18 /// ```
19 /// # #[macro_use] extern crate static_assertions;
20 /// # fn main() {}
21 /// # #[cfg(any(unix, linux))]
22 /// assert_cfg!(any(unix, linux), "There is only support for Unix or Linux");
23 ///
24 /// // User needs to specify a database back-end
25 /// # #[cfg(target_pointer_width = "0")] // Impossible
26 /// assert_cfg!(all(not(all(feature = "mysql", feature = "mongodb")),
27 ///                 any(    feature = "mysql", feature = "mongodb")),
28 ///             "Must exclusively use MySQL or MongoDB as database back-end");
29 /// ```
30 ///
31 /// Some configurations are impossible. For example, we can't be compiling for
32 /// both Unix _and_ Windows simultaneously:
33 ///
34 /// ```compile_fail
35 /// # #[macro_use] extern crate static_assertions;
36 /// # fn main() {
37 /// assert_cfg!(all(unix, windows), "No, that's not how it works! ಠ_ಠ");
38 /// # }
39 /// ```
40 #[macro_export]
41 macro_rules! assert_cfg {
42     () => {};
43     ($($cfg:meta)+, $msg:expr) => {
44         #[cfg(not($($cfg)*))]
45         compile_error!($msg);
46     };
47     ($($cfg:tt)*) => {
48         #[cfg(not($($cfg)*))]
49         compile_error!(concat!("Cfg does not pass: ", stringify!($($cfg)*)));
50     };
51 }
52