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

Immutable variables

Rust—like many functional languages—embraces immutable variables. They are the default, and changing mutability requires explicit declaration with mut, which tells the compiler what the variable is going to be used for (reading or writing).

Functional programming languages are known for facilitating the ability to work concurrently, thanks to immutability guarantees; reading data does not produce side effects! Requiring explicit mutability gives the compiler a chance to check where and if mutability is required, and therefore whether a data race may occur.

This results in compile-time warnings and errors instead of crashes and strange race conditions at runtime, something that many production users appreciate. In short, it's easier to think through your code if mutability is a (rare) option instead of the norm.

主站蜘蛛池模板: 甘泉县| 辽阳市| 宣威市| 花莲县| 威远县| 时尚| 安塞县| 镇雄县| 邮箱| 建平县| 德江县| 娱乐| 吴江市| 彭山县| 崇州市| 得荣县| 奉贤区| 朝阳市| 商洛市| 莱州市| 镇江市| 襄垣县| 乌拉特前旗| 白沙| 清水河县| 嵊泗县| 武清区| 哈密市| 阳西县| 新野县| 衡阳市| 称多县| 萍乡市| 内乡县| 南川市| 青川县| 康马县| 墨竹工卡县| 民县| 桃园市| 三台县|