Understanding Rust's ownership system can be tough at first, but once you think of variables as bank cards and values as bank accounts, everything starts to make sense.
1. 💳 Ownership (Move)
let card_one = String::from("Bank Account: PIN 1234"); let card_two = card_one; println!("{}", card_one); println!("{}", card_two);👉 Only one card can own the account at a time. When ownership is moved, the old card becomes useless.
2. 📷 Cloning
let card_one = String::from("Bank Account"); let card_two = card_one.clone(); println!("{} and {}", card_one, card_two);👉 Now we have two cards each pointing to its own separate account. The accounts just happen to hold similar info, but they are distinct items.
3. 🕵️ Immutable Borrowing (Read-Only)
let card_one = String::from("Bank Account"); let card_copy_one = &card_one; let card_copy_two = &card_one; println!("{}, {}", card_copy_one, card_copy_two );👉 Multiple read-only copies are fine. No one can change anything, but everyone can check the balance.
4. ✍️ Mutable Borrowing (Exclusive Write Access)
Let's say you want to change your account info:
let mut card_one = String::from("Bank Account"); let editor = &mut card_one; println!("{}", card_one); editor.push_str(" - PIN Updated");But when the edit is complete: You are free to use it
let mut card_one = String::from("Bank Account"); let editor = &mut card_one; editor.push_str(" - PIN Updated"); println!("{}", card_one);Note: After the financial assistant is done changing your account and handed over ownership to you, they are not allowed to use their mutable borrow to read or update your bank account anymore.
let mut card_one = String::from("Bank Account"); let editor = &mut card_one; editor.push_str(" - PIN Updated"); println!("{}", card_one); println!("{}", editor);👉 Only one mutable borrow is allowed at a time. And during that time, the owner can't access the card.
Summary
Only one owner (card) at a time.
You can clone to make a copy (new card + new account).
You can borrow immutably multiple times to read, but not change.
You can borrow mutably only once, exclusively, to edit.
Rust is like a strict bank that always knows who's holding the card, and won’t let you mess up account access rules.
🧠 Once you understand the card/account model, you understand Rust’s safety rules.
.png)


