What is the difference between immutable and const variables in Rust?

前端 未结 6 2106
广开言路
广开言路 2020-12-13 17:12

I learned that if a variable is not explicitly declared mutable using mut, it becomes immutable (it cannot be changed after declaration). Then why do we have th

6条回答
  •  时光取名叫无心
    2020-12-13 17:42

    const is for compile-time constants with everything that entails. For example, you can create a fixed-sized array whose size is a const, but you can't do that with a let binding. Of course, this also means that you can put far, far more things into a let binding than into a const.

提交回复
热议问题