start work on ownership model

This commit is contained in:
2026-10-02 15:52:53 +01:00
parent a881f5bca7
commit 735bcaac3b
5 changed files with 32 additions and 1 deletions
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "ownership"
edition.workspace = true
version.workspace = true
license.workspace = true
[dependencies]
+17
View File
@@ -0,0 +1,17 @@
# Ownership
## The Stack and the Heap
The stack is fast memory which follows the `Last in First out (LIFO)` principle.
On the stack, only data with a know size can live. If it can shrink or grow, then the data must be allocated to the heap.
When data is allocated to the heap, it gets a pointer to an address in memory.
Keeping track of these things are really important in languges like C. Other programming languages like Go use a garbage collector (GC)
which cleans up data in memory on a regular basis.
Rust does neither. It uses `Ownership` to manage memory and data, so each piece of data has an owner, and when that owner gets out of scope, the value is dropped.
## Ownership rules
- Each value in Rust has an owner.
- There can only be one owner at a time.
- When the owner goes out of scope, the value will be dropped.
## Variable Scope
+3
View File
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}