computer_knowledge_notes/Languages/Rust/attribute/attribute.md

58 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#### 属性
语法:
```rust
#![Attr] // 内部属性,作用于声明属性的地方
#[Attr] // 外部属性,作用于属性之后的东西
```
分类:
- 内建属性
- 宏属性
- 派生宏辅助属性
- 工具属性
可应用于:
##### 元条目属性语法
##### 活跃的或内部的
##### 工具属性
##### 内建属性
```rust
// 条件编译
cfg // 控制条件编译
cfg_attr // 有条件地包含属性
// 测试
// 派生
derive // 自动特性实现
// 宏
macro_use // 扩展宏的可见性或从其它crate导入宏。
// 诊断
allow, warn, deny, forbid // 改变默认的检测级别
allow(c) // 撤销对c的检查这样违规行为将不会被报告
warn(c) // 对c的违规行为将发出警告但仍然会继续编译
deny(c) // 如遇到c的违规行为将发出error信号
forbid(c) // 类似于deny(c),且禁止更改检测级别
// ABI链接符号FFI
no_main // 不会加载"main"标记
no_mangle // 禁止符号名编码
// 代码生成
// 文档
// 预加载
no_std // 不会预加载std
// 模块
// 限制
// 运行时
global_allocator // 实现了GlobalAlloc特性的静态条目用此属性来设置全局内存分配器.
// 性质
feature // 使能开发中的,或实验性的编译器属性。
// 类型系统
```