Rust 程序设计语言 简体中文版 1.85.0
let result = add(2, 2); assert_eq!(result, 4); } } 上述代码就是自动生成的测试模块。cfg 属性代表配置(configuration),它告诉 Rust 接下来 的项只有在给定特定配置选项时,才会被包含。在这种情况下,配置选项是 test,即 Rust 所 提供的用于编译和运行测试的配置选项。通过使用 cfg 属性,Cargo messenger.send("Error: You are over your quota!"); } else if percentage_of_max >= 0.9 { self.messenger .send("Urgent warning: You've used up over 90% of your quota!"); percentage_of_max >= 0.75 { self.messenger .send("Warning: You've used up over 75% of your quota!"); } } } 示例 15-20:一个记录某个值与最大值差距的库,并根据此值的特定级别发出警告 这些代码中一个重要部分是拥有一个方法0 码力 | 562 页 | 3.23 MB | 10 天前3
共 1 条
- 1