Rust 条件编译属性覆盖了多少行? [英] How many lines are covered by the Rust conditional compilation attribute?
问题描述
我正在尝试使用条件编译语句.除了定义一个只应存在于调试版本中的函数之外,我想定义一组仅存在于调试版本中的变量/常量/类型.
I'm trying to use a conditional compilation statement. Beyond defining a function that should only exist in a debug build, I want to define a set of variables/constants/types that only exist in the debug build.
#[cfg(debug)]
pub type A = B;
pub type B = W;
#[cfg(other_option)]
pub type A = Z;
pub type B = I;
let test = 23i32;
在这种情况下,条件编译属性实际上覆盖"了多少行?它只有一个(在这种情况下我会期望什么)?有没有办法确保整个代码块(包括变量、类型和两个函数)都被条件覆盖?
How many lines are actually "covered" by the conditional compile attribute in this case? Is it only one (what I would expect in this context)? Are there ways to ensure that a whole block of code (including variables, types and two functions) is covered by the condition?
推荐答案
一个 #[attribute]
只适用于下一个 item.请参阅 Rust 手册.
An #[attribute]
only applies to the next item. Please see the Rust book.
编辑:我认为目前不可能在任意数量的声明中传播一个属性.
Edit: I don't think it is currently possible to spread an attribute over an arbitrary number of declarations.
有关属性及其应用的其他深入信息可以在 Rust 参考.
Additional, in-depth information on attributes and their application can be found at Rust reference.
这篇关于Rust 条件编译属性覆盖了多少行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!