Rust TutorialLesson 18Free preview
Rust Scope
This lesson is part of Rust · All levels
Summary
This lesson discusses the concept of scope and its impact on the lifespan of memory data. In Rust, a variable is only valid as long as it is within the scope of curly braces where the variable is declared. When the scope ends, Rust automatically releases the variable memory via a drop mechanism.
Key points
- Scope is determined by the curly braces '{' and '}'
- The variable is valid from the declaration point to the end of the block of scope
- When a variable is out of scope, automatic memory is released
- The 'drop' function is automatically called by Rust when the memory allocation ends
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.