【发布时间】:2020-06-12 18:07:27
【问题描述】:
我想知道如何在cfg! 宏下使用条件编译模块。我正在尝试这个:
pub fn f() { ... }
#[cfg(feature = "x")]
pub mod xmodule {
pub fn f() { ... }
}
pub fn test() {
if cfg!(feature = "x") {
xmodule::f();
} else {
f();
};
}
当我使用cargo check --features x 编译它时它工作正常,但如果我不启用该功能它会失败并出现以下错误:
use of undeclared type or module `xmodule`
是我做错了什么还是编译不够聪明,无法理解如果未设置该功能则不应使用该模块?
【问题讨论】:
标签: rust conditional-compilation