January 2019
Beginner to intermediate
554 pages
13h 31m
English
Before we go further into ownership, we need to get a brief idea of scopes, which might be familiar to you already if you know C, but we'll recap it here in the context of Rust, as ownership works in tandem with scopes. So, a scope is nothing but an environment where variables and values come into existence. Every variable you declare is associated with a scope. Scopes are represented in code by braces {}. A scope is created whenever you use a block expression, that is, any expression that starts and ends with braces {}. Also, scopes can nest within each other and can access items from the parent scope, but not the other way around.
Here's some code that demonstrates multiple scopes and values:
// scopes.rsfn main() { Read now
Unlock full access