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