– | 名称 | 导航 | |
---|---|---|---|
√ | 枚举 | Option | Rust之option、result枚举类型 |
√ | 枚举 | Result | Rust之option、result枚举类型 |
√ | 枚举变体 | Some | Rust之option、result枚举类型 |
√ | 枚举变体 | Ok | Rust之option、result枚举类型 |
√ | 枚举变体 | Err | Rust之option、result枚举类型 |
√ | 关键字 | match | Rust之match、let、lf-let关键字 |
√ | 关键字 | let | Rust之match、let、lf-let关键字 |
√ | 关键字 | if let | Rust之match、let、lf-let关键字 |
√ | 接口 | Error | Rust之Error接口(trait) |
√ | 结构体 | fmt::Formatter | Rust之Error接口(trait) |
√ | 接口 | From | Rust之From、Into接口(trait) |
√ | 接口 | Into | Rust之From、Into接口(trait) |
√ | 泛型函数 | Rust之泛型函数 | |
☐ | 模式 | 宏 | Rust高级进阶之宏定义 |
Question:宏和函数有什么区别?
带着这个问题一起看
rust中的宏定义
- 分为两大类
- 声明式宏(
declarative macros
)macro_rules!
- 特点是:在编译时进行宏展开,替代原代码
- 三种过程宏(
procedural macros
)#[derive]
自定义宏,可以为目标结构体或枚举派生指定的代码,如 Debug 特征- 属性宏(
Attribute-like macro
),用于为目标添加自定义的属性 - 函数宏(
Function-like macro
),看上去就像是函数调用
- 声明式宏(