rust - 如何有条件地启用基于 cfg 的 Rust 功能?
问题描述
我想使用#![feature(custom_test_frameworks)]
,但如果可能的话,只能通过有条件地启用它#[cfg(not(target_os = "custom_os_name"))]
。我仍然希望可以选择使用 rusts libtest 在我的主机系统上直接运行一些测试,但显然我不允许通过以下方式修改功能cfg
:
错误信息:
note: inner attributes, like `#![no_std]`, annotate the item enclosing them,
and are usually found at the beginning of source files. Outer attributes, like
`#[test]`, annotate the item following them.
有没有其他方法可以有条件地启用“内部属性”?
解决方案
您可以使用#[cfg_attr]
基于其他一些功能来应用属性。
在您的情况下,您可以执行以下操作:
#![cfg_attr(
not(target_os = "custom_os_name"),
feature(custom_test_frameworks)
)]
推荐阅读
- unity3d - Unity 对象检测:梭子鱼、MobileNET 和网络摄像头
- mysql - 如何联合 2 个表但根据条件选择值?
- python - 如何将我从 API 收到的行插入 mysql
- python - 为什么我的 Python 条件函数内不起作用?
- c# - BluetoothLEAdvertisementWatcher 未收到广告负载
- r - 数据框中每个参与者之间的地理空间距离矩阵?
- discord - Discord 机器人添加角色
- javascript - 努力使异步函数等待数据库响应
- javascript - 如何在 input type="number" 元素中获取插入符号的位置?
- mysql - 使用 SQL 查询进行多次查找和替换