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

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.

主站蜘蛛池模板: 松溪县| 巩义市| 涿州市| 沅陵县| 天津市| 敦化市| 屯留县| 理塘县| 石嘴山市| 万荣县| 马鞍山市| 新津县| 大港区| 改则县| 景洪市| 青铜峡市| 临朐县| 穆棱市| 淳安县| 天镇县| 宝鸡市| 青州市| 平阳县| 文化| 兖州市| 南川市| 阜新市| 留坝县| 滨州市| 和平县| 潞西市| 大城县| 苍南县| 博乐市| 如东县| 尚志市| 万全县| 平定县| 拉孜县| 平定县| 霍城县|