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 25,600 courses taught by industry experts.
Demo: Shadowing variables - Rust Tutorial
From the course: Rust Programming: From Fundamentals to Advanced Concepts with AI-Assisted Development
Demo: Shadowing variables
- Shadowing variables or variable assignment. Using shadowing is something that is common in other programming languages, and rust definitely allows you to do that. What is shadowing it's the ability to define a variable, like in this case, height, which we've seen before, and then reassign it to something else, to some other value. Now, this can also be done by reusing the previous hide value or variable defined right here. So all of this is possible, so you can have from here to here, and that definitely works. Now we're getting a, a red curly underline. What's the deal here? What is one of the problems? We've seen this before. Are you able to catch what is going on here? It is a very simple problem. We're modifying something here that perhaps we shouldn't be modifying. So we're going to run it here. And there we go. We're assigning something to a, an immutable variable. Of course, I actually forgot to make it mutable. So now why don't we go ahead and make it mutable. So I'm going…
Contents
-
-
-
-
-
-
(Locked)
Introduction to Rust38s
-
(Locked)
Demo: Create a new Rust project5m 37s
-
(Locked)
Demo: Overview of project files6m
-
(Locked)
Demo: Basic components of Rust code6m 27s
-
(Locked)
Demo: Variable assignment and immutability6m 17s
-
(Locked)
Demo: Basics of control flow4m 7s
-
(Locked)
Demo: Shadowing variables5m 52s
-
(Locked)
Summary of introduction to Rust47s
-
(Locked)
-
-
-
-
-
-
-
-
-