-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathmain.rs
More file actions
27 lines (23 loc) · 704 Bytes
/
Copy pathmain.rs
File metadata and controls
27 lines (23 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// OWNERSHIP
//
// MAIN IDEA:
//
// "SCOPE owns a VARIABLE owns a VALUE"
//
// + A value lives on memory.
// + It can move between variables.
// + A variable can be an owner of a value.
// + A variable comes in and goes out of a scope.
//
// RULES:
// + Each value has a single owner.
// + Ownership can move between variables.
// + When the owner goes out of scope, the value will be dropped.
fn main() {
scope();
}
fn scope() { // s isn't declared yet. not valid here.
let s = "hi"; // s comes into scope here.
println!("{}", s); // work with s however you want.
} // s goes out of scope.
// you can no longer use it.