- Rust Standard Library Cookbook
- Jan Nils Ferner Daniel Durante
- 158字
- 2021-08-27 19:45:02
How it works...
Nearly every type in Rust has a Default implementation. When you define your own struct that only contains elements that already have a Default, you have the option to derive from Default as well [42]. In the case of enums or complex structs, you can easily write your own implementation of Default instead [55], as there's only one method you have to provide. After this, the struct returned by Default::default() is implicitly inferrable as yours, if you tell the compiler what your type actually is. This is why in line [3] we have to write foo: i32, or else Rust wouldn't know what type the default object actually should become.
If you only want to specify some elements and leave the others at the default, you can use the syntax in line [29]. Keep in mind that you can configure and skip as many values as you want, as shown in lines [33 to 37].
- 第三代移動通信
- Protel DXP 2004電路設(shè)計基礎(chǔ)與典型范例
- RFID 重大工程與國家物聯(lián)網(wǎng)(第3版)
- 現(xiàn)代移動通信技術(shù)及應(yīng)用
- Android應(yīng)用開發(fā)從入門到精通
- 圖表細(xì)說電路回路法識圖
- .NET 微信公眾平臺開發(fā)教程
- 3D顯示技術(shù)
- 移動通信天線技術(shù)與工程應(yīng)用
- SDH和DWDM設(shè)備操作與維護
- 教你快速看懂電子電路圖
- 三菱FX系列PLC數(shù)據(jù)通信及測控應(yīng)用
- 電子科學(xué)與技術(shù)導(dǎo)論
- 基于Kotlin的Android應(yīng)用程序開發(fā)
- IT支撐系統(tǒng)與關(guān)鍵技術(shù)