I have seen people write things like this often:
This can get unwieldy.
There are two features that you can combine to make this simpler and smaller:
Here’s how it goes when combined:
And so in this example, on Unix platforms it’ll load unix.rs as the
platform module, while on Windows it’ll load windows/mod.rs [FYI, if you went for windows/mod.rs because
windows contained other modules inside it, know that from Rust 1.30 onwards you can actually have a file named windows.rs beside that windows/ subdirectory, instead of it having to be windows/mod.rs. The Rust Reference even recommends switching to this new style, though I’m not sold on it.] as the
platform module, and so in either case it can subsequently do a reexport if desired.
Mind you, for complex enough specifications, even the single mod version can still be messy:
And truly they can get much worse than that; the worst cases I’ve seen might even be enough for me to reach for cfg-if (which I am loath to do—I reckon the significant majority of its uses are unwarranted) and separate
mod statements, rather than using