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

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.

主站蜘蛛池模板: 沁阳市| 万宁市| 旺苍县| 安新县| 余江县| 华蓥市| 绥芬河市| 四子王旗| 商都县| 穆棱市| 石首市| 锡林浩特市| 西和县| 平凉市| 白银市| 蓬安县| 天峨县| 苍溪县| 黑河市| 台北县| 象州县| 汤原县| 垣曲县| 云安县| 平泉县| 千阳县| 阜宁县| 常德市| 外汇| 柳江县| 阿图什市| 衢州市| 白玉县| 大理市| 汪清县| 驻马店市| 舟曲县| 门源| 雷波县| 临西县| 桦甸市|