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
Generated
+4
View File
@@ -48,6 +48,10 @@ version = "0.2.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
[[package]]
name = "ownership"
version = "0.1.0"
[[package]]
name = "ppv-lite86"
version = "0.2.21"
+1 -1
View File
@@ -1,5 +1,5 @@
[workspace]
members = ["common-programming-concepts", "common-programming-concepts-fibonacci", "common-programming-concepts-temp-converter", "common-programming-concepts-twelve-days-of-christmas","guessing-game"]
members = ["common-programming-concepts", "common-programming-concepts-fibonacci", "common-programming-concepts-temp-converter", "common-programming-concepts-twelve-days-of-christmas","guessing-game", "ownership"]
resolver = "2"
[workspace.package]
+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!");
}