macro_rules! assert_cfg {
    () => { ... };
    ($($cfg:meta)+, $msg:expr $(,)?) => { ... };
    ($($cfg:tt)*) => { ... };
}
Expand description

Asserts that a given configuration is set.

Examples

A project will simply fail to compile if the given configuration is not set.

// We're not masochists
assert_cfg!(not(target_pointer_width = "16"));

If a project does not support a set of configurations, you may want to report why. There is the option of providing a compile error message string:

assert_cfg!(any(unix, windows), "There is only support for Unix or Windows");

// User needs to specify a database back-end
assert_cfg!(all(not(all(feature = "mysql", feature = "mongodb")),
                any(    feature = "mysql", feature = "mongodb")),
            "Must exclusively use MySQL or MongoDB as database back-end");

Some configurations are impossible. For example, we can’t be compiling for both macOS and Windows simultaneously:

assert_cfg!(all(target_os = "macos",
                target_os = "windows"),
            "No, that's not how it works! ಠ_ಠ");