- Rust Standard Library Cookbook
- Jan Nils Ferner Daniel Durante
- 155字
- 2021-08-27 19:45:03
How it works...
If a struct provides a method called new that returns Self, the user of the struct will not configure or depend upon the members of the struct, as they are considered to be in an internal hidden state.
In other words, if you see a struct that has a new function, always use it to create the structure.
This has the nice effect of enabling you to change as many members of the struct as you want without the user noticing anything, as they are not supposed to look at them anyway.
The other reason to use this pattern is to guide the user to the correct way of instantiating a struct. If one has nothing but a big list of members that have to be filled with values, one might feel a bit lost. If one, however, has a method with only a few self-documenting parameters, it feels way more inviting.
- 現(xiàn)代數(shù)據(jù)通信技術(shù)與應(yīng)用
- cdma2000 1x/EV-DO通信網(wǎng)絡(luò)規(guī)劃與設(shè)計(jì)
- 網(wǎng)絡(luò)時(shí)代的電信監(jiān)管
- 短視頻制作實(shí)戰(zhàn) 策劃 拍攝 制作 運(yùn)營(yíng)(全彩慕課版)
- 無(wú)線定位系統(tǒng)
- 信息通信業(yè)的數(shù)字化發(fā)展之路
- 輕松實(shí)現(xiàn)Altium Designer板級(jí)設(shè)計(jì)與數(shù)據(jù)管理
- 精通Android 5 多媒體開發(fā)
- 風(fēng)云三號(hào)氣象衛(wèi)星地面應(yīng)用系統(tǒng)工程技術(shù)和實(shí)踐
- 人工智能超密集移動(dòng)通信系統(tǒng)
- LED照明電路設(shè)計(jì)100例
- 電子產(chǎn)品制作技術(shù)與技能實(shí)訓(xùn)
- 應(yīng)用商店核心用戶在線評(píng)論對(duì)消費(fèi)者更新決策的影響研究
- 云計(jì)算安全
- Final Cut Pro X實(shí)戰(zhàn)從入門到精通