[][src]Macro dirmod_docsrs_test::os

os!() { /* proc-macro */ }

Includes modules based on the target_os cfg attribute.

Each module named $mod is conditionally compiled with the #[cfg(target_os = $mod)] option, allowing OS-specific module files/directories like windows.rs, unix.rs, etc.

Note that this macro does not check for nonexistent target_os values, so incorrect usage will not lead to any warnings (and likely never compile the incorrect modules). See this page for a list of possible values.

It is usually a good idea to provide the use keyword and expose the same API methods in all specific operating systems, preventing the need of target_os checking outside the crate.

Parameters

This example is not tested
os!($vis [use] [|| [$error]]);

os! accepts a visibility and an optional use keyword, with the same meaning as those in all!.

The optional || $error clause adds the code to check if at least one of the modules is compiled; otherwise, compile_error! would be triggered. $error should be a string literal. If $error is omitted, it is replaced by the default message "target_os must be one of \"xxx\", \"yyy\", ...", where xxx and yyy are the available modules.

os! does not provide any filtering, and is intended for parent modules with only platform-specific submodules. If non-OS-specific modules are desired, consider moving the OS-specific modules to the same directory.

Examples

This example is not tested
os!(priv ||);
This example is not tested
os!(pub use || "Unsupported operating system");

If none of the modules in the directory get compiled, compilation would abort with the message "Unsupported operating system".