This is more a style question but still interesting. Is it possible to group things so the attribute is only there once?
For instance, in the following code I am using the same attribute three times:
#[cfg(target_os = "linux")]
extern crate nix;
#[cfg(target_os = "linux")]
extern crate libc;
#[cfg(target_os = "linux")]
use std::{
mem,
};
You can use a helper module to cfg the entire module and then reexport its contents:
#[cfg(target_os = "linux")]
mod linux {
extern crate nix;
extern crate libc;
pub use std::{
mem,
};
}
#[cfg(target_os = "linux")]
use linux::*;
You still have to mention the cfg twice though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With