- 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].
- 深入理解Android:Java虛擬機ART
- 智慧城市:城市品質(zhì)新思維
- 電子產(chǎn)品調(diào)試技能上崗實訓(xùn)
- 5G 空口特性與關(guān)鍵技術(shù)
- 精通Android 5 多媒體開發(fā)
- Untangle Network Security
- 5G大規(guī)模天線增強技術(shù)
- LED照明電路設(shè)計100例
- 電子技術(shù)(第3版)
- iOS 7開發(fā)快速入門
- 特高壓實踐:GIL綜合管廊的建設(shè)與維護
- 多媒體通信技術(shù)與應(yīng)用
- Microduino實戰(zhàn)
- 電子工程師必備:元器件應(yīng)用寶典(強化版)
- 電氣控制及變頻技術(shù)應(yīng)用