【发布时间】:2020-02-24 09:27:14
【问题描述】:
就我对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::*;
有没有更清洁的方法来做到这一点?
【问题讨论】:
-
好吧,在这种情况下,您可以将这些导入合并到一行:
use termion::{coloe, style, screen::*}。但一般来说它可能无法回答您的问题。 -
@edwardw,真的,我正在寻找更一般的答案
-
旁注:至少有one crate在解决终端跨平台使用问题。
-
@DenysSéguret 谢谢我不知道!
标签: rust attributes conditional-compilation