It'd be really nice if we could do something like:
#[cfg(feature = "abc")]
{
extern crate x;
extern crate y;
mod z;
use z::{a, b, c};
}
Right now, we have to attach the attribute to every item, which is a bit redundant. We can put things in a module and then re-export them, but it'd be nice if we could do something like this instead.
With https://github.com/alexcrichton/cfg-if you can make it look like:
#[macro_use] extern crate cfg_if;
cfg_if! {
if #[cfg(feature = "abc")] {
extern crate x;
extern crate y;
mod z;
use z::{a, b, c};
}
}
@withoutboats Would anonymous modules do this? As something like
#[cfg(feature = "abc")]
mod {
extern crate x;
extern crate y;
mod z;
use z::{a, b, c};
}
I considered anonymous modules, but the main issue is that things like extern crate, etc. wouldn't semantically fit in a module. It could work, though.
@clarcharr it's actually a pattern, albeit an uncommon one, to put extern crates in submodules.
@ubsan wait, is that actually allowed? huh.
I think this is #2377 so I'm closing in favor of that.
Most helpful comment
With https://github.com/alexcrichton/cfg-if you can make it look like: