dirmod
dirmod copied to clipboard
Conditional compilation by suffix
trafficstars
The current dirmod::os!() macro requires a structure like this:
- mod.rs - includes foo, bar, qux
- foo.rs
- bar.rs
- qux/
- qux/mod.rs - dirmod::os!()
- qux/windows.rs
- qux/unix.rs
It might be preferrable to have a structure like this:
- mod.rs - includes foo, bar, qux
- foo.rs
- bar.rs
- qux_windows.rs
- qux_unix.rs
This can be activated by providing a flag like with family suffix; in the dirmod::all!() call in mod.rs.
If qux.rs is also present, there are two possible solutions:
- trigger a compile error
- declare a module like this:
$vis mod qux {
#[path = "qux.rs"] mod _common;
pub use _common::*;
#[cfg(target_family = "windows")] #[path = "qux_windows.rs"] mod _windows;
pub use _windows::*;
#[cfg(target_family = "unix")] #[path = "qux_unix.rs"] mod _unix;
pub use _unix::*;
}
The former is preferred as it leads to less confusion. In particular, the latter solution might be confusing in that the exports from qux_windows.rs and qux_unix.rs actually cannot be used in qux.rs.