例如,在下面的代码中,我使用同一属性三次:
#[cfg(target_os = "linux")] extern crate nix; #[cfg(target_os = "linux")] extern crate libc; #[cfg(target_os = "linux")] use std::{ mem, };
可以使用帮助器模块来配置整个模块,然后重新导出其内容:
#[cfg(target_os = "linux")] mod linux { extern crate nix; extern crate libc; pub use std::{ mem, }; } #[cfg(target_os = "linux")] use linux::*;