将锈属性应用于多条线

问题描述 投票:1回答:2

据我对the Rust documentation的最佳理解,属性仅应用于直接在属性之后的行。因此,例如我想conditionally compile行我可以这样做:

#[cfg(target_family = "unix")]
use termion::{color, style};

当我想有条件地编译两行时会发生什么?

#[cfg(target_family = "unix")]
use termion::{color, style};
#[cfg(target_family = "unix")]
use termion::screen::*;

是否有更清洁的方法?

rust attributes conditional-compilation
2个回答
3
投票

我所掌握的知识没有一般的分组答案,但是有特定的解决方案。

通常,您只能使用一个块:


0
投票

您可以通过cfg_if crate完成此操作。

© www.soinside.com 2019 - 2024. All rights reserved.