← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6074.o · 生成模型:未记录

绑定默认不可变

理解等级:初级

Rust 默认禁止给已初始化的普通绑定再次赋值。let mut 表明该绑定可以更新,让读者能在声明处识别随时间变化的数据。一个有意更新的绑定仍有固定的类型。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 常见编程概念 Variables and Mutability · 查看原书依据

      But mutability can be very useful, and can make code more convenient to write. Although variables are immutable by default, you can make them mutable by adding mut in front of the variable name as you did in Chapter 2. Adding mut also conveys intent to future readers of the code by indicating that other parts of the code will be changing this variable’s value.

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第03章 常见编程概念(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c03.xhtml`,块 0018) - 结论依据:原文说明 mut 允许改变绑定值并向读者传达改动意图。 - 原始内容:But mutability can be very useful, and can make code more convenient to write. Although variables are immutable by default, you can make them mutable by adding mut in front of the variable name as you did in Chapter 2. Adding mut also conveys intent to future readers of the code by indicating that other parts of the code will be changing this variable’s value.