官术网_书友最值得收藏!

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].

主站蜘蛛池模板: 石台县| 堆龙德庆县| 象州县| 都兰县| 五家渠市| 湄潭县| 珠海市| 台州市| 乌审旗| 望奎县| 阜平县| 成安县| 纳雍县| 龙岩市| 东城区| 基隆市| 延庆县| 瓮安县| 太湖县| 武夷山市| 闽侯县| 四会市| 海伦市| 会宁县| 错那县| 佛冈县| 徐水县| 濮阳市| 西吉县| 南华县| 华坪县| 阳东县| 玛沁县| 尼玛县| 延边| 扎兰屯市| 郁南县| 余庆县| 丹江口市| 内黄县| 佛冈县|