From the course: Rust Programming: From Fundamentals to Advanced Concepts with AI-Assisted Development

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Demo: Variable assignment and immutability

Demo: Variable assignment and immutability

- [Instructor] Let's see how variable the assignment works in Rust and some of the problems that we may get into when we're running Rust and running the compiler. And although we're not looking specifically at a whole section for compiler errors, we'll be running these and going through compiler errors as we move along. So we have here a main function and we'll always have a main function for these short examples. And variable assignment is very straightforward. You use the let word, or keyword, and then the name of the variable, and you pass in here what you want. In this case, this is a string, and we're using the semicolon to indicate that that's the end of the statement. And then here we're defining weight 190. Now, we're letting the compiler infer what types we're using. We are not kind of like required to do that, so that's fine. And we have here, and I just saved, and we have here like a curly, red, curly underline. So something's going on. We're able to do expressions. In this…

Contents