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

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.

主站蜘蛛池模板: 开封市| 垫江县| 黔江区| 晋江市| 新平| 威海市| 宁波市| 临湘市| 康马县| 温州市| 揭东县| 永年县| 承德市| 巢湖市| 平湖市| 浑源县| 武乡县| 左云县| 宁化县| 宁安市| 宁陕县| 类乌齐县| 康马县| 石楼县| 天祝| 高陵县| 安龙县| 林芝县| 新乡市| 葫芦岛市| 汽车| 汉中市| 青阳县| 芜湖县| 巴彦县| 治多县| 嵩明县| 高邮市| 渝中区| 溧水县| 张北县|