[Rust Guide] 3.1. Variables and Mutability
3.1.0. Before the Main Content Welcome to Chapter 3 of Rust self-study. There are 6 sections in total: Variables and Mutability (this article) Data Types: Scalar Types Data Types: Compound Types Fu...
![[Rust Guide] 3.1. Variables and Mutability](https://media2.dev.to/dynamic/image/width=1200,height=627,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6drac9gshfy70xi1ebje.png)
Source: DEV Community
3.1.0. Before the Main Content Welcome to Chapter 3 of Rust self-study. There are 6 sections in total: Variables and Mutability (this article) Data Types: Scalar Types Data Types: Compound Types Functions and Comments Control Flow: if else Control Flow: Loops Through the small game in Chapter 2 (beginners who haven’t read it are strongly recommended to do so), you should already have learned the basic Rust syntax. In Chapter 3, we will go one level deeper and understand general programming concepts in Rust. If you like it, please like, bookmark, and follow 3.1.1. Declaring Mutable/Immutable Variables Variables are declared using the let keyword By default, variables are immutable. The following is an incorrect example, with the error shown in the comment: fn main(){ let machine = 6657; machine = 0721; // Error: cannot assign twice to immutable variable println!("machine is {}", machine); } Add mut after let to declare a mutable variable. The following is a correct example: fn main(){ l