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

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

主站蜘蛛池模板: 赤水市| 吴忠市| 吕梁市| 河曲县| 永城市| 隆子县| 泰来县| 遂溪县| 弥勒县| 江川县| 十堰市| 南阳市| 绥宁县| 莱阳市| 赤峰市| 仲巴县| 永顺县| 周宁县| 英吉沙县| 玉山县| 大石桥市| 邯郸县| 泸定县| 湘潭市| 忻州市| 叙永县| 方正县| 临澧县| 平安县| 肥东县| 浪卡子县| 汾西县| 武清区| 怀远县| 抚州市| 区。| 横山县| 佳木斯市| 柏乡县| 新绛县| 沂南县|