I also think it would be useful, and took a look at some of the discussion and saw that gnzlbg implemented match_cfg, which I haven't seen before. It requires more vertical space compared to nested else if
clauses, but has some potential. I'm wondering if there has been any discussion of trimming some of the punctuation and syntax. For example, remove the repeating cfg
like:
match_cfg! {
(target_os = "vxworks") => {
mod vxworks;
pub use self::vxworks::*;
}
unix => {
mod unix;
pub use self::unix::*;
}
windows => {
mod windows;
pub use self::windows::*;
}
(target_os = "cloudabi") => {
mod cloudabi;
pub use self::cloudabi::*;
}
(target_os = "hermit") => {
mod hermit;
pub use self::hermit::*;
}
(target_os = "wasi") => {
mod wasi;
pub use self::wasi::*;
}
(target_arch = "wasm32") => {
mod wasm;
pub use self::wasm::*;
}
all(target_vendor = "fortanix", target_env = "sgx") => {
mod sgx;
pub use self::sgx::*;
}
_ => {
mod unsupported;
pub use self::unsupported::*;
}
}
It looks like the cfg_match
crate does something similar. Certainly a few options to explore.