https://github.com/aabbtree77/ownership
Testing the borrow checker.
https://github.com/aabbtree77/ownership
analogy borrow-checker chatgpt4 education examples immutability ownership
Last synced: about 1 year ago
JSON representation
Testing the borrow checker.
- Host: GitHub
- URL: https://github.com/aabbtree77/ownership
- Owner: aabbtree77
- License: mit
- Created: 2025-02-15T14:36:33.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-08T00:18:51.000Z (over 1 year ago)
- Last Synced: 2025-04-14T01:17:38.560Z (about 1 year ago)
- Topics: analogy, borrow-checker, chatgpt4, education, examples, immutability, ownership
- Language: Rust
- Homepage:
- Size: 1.77 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
> "I've got thirteen channels of shit on the T.V. to choose from..."
>
> — *Pink Floyd, 1979*
## Introduction
The codes show numerous ways to modify a list in Rust, to see what the borrow checker is about.
## Basic
```console
cd basic
rustc basic.rs && ./basic
```
1. Mutable Borrow - Safe lock: You open, modify, and close it.
2. Immutable Borrow - Hotel room: You can look but not change anything.
3. Ownership Transfer - Moving van: You give away the whole thing.
## Advanced
```console
cd advanced
cargo run
```
1. Mutable Borrow - Safe lock: You open, modify, and close it.
2. Immutable Borrow - Hotel room: You can look but not change anything.
3. Ownership Transfer - Moving van: You give away the whole thing.
4. Box - Storage unit: You keep ownership but store it elsewhere.
5. Rc - Shared Library: Multiple users can read it but not modify it.
6. Arc - Secure Webpage: Many threads access read-only content.
7. RefCell - Restroom: Multiple access, but only one can modify at a time.
8. Mutex - Safe Lock: One at a time access in multi-threaded scenarios.
9. Async - Server request queue: Processing data asynchronously.
10. Async Lifetime - Managing a connection that outlives a function.
11. Gc - Smart Trash Bin: It will be cleaned when unused.