第一次使用 Rust 是在改寫區塊鏈 Side Project。主要是利用 Hyperledger Sawtooth,原先使用 Go,後來改用 Rust。發現 Rust 的速度有比較快,但不好學。這二、三年來斷斷續續重頭學習,也一直沒有好好整理。最近又再重頭學習一次,並且把公司內原本 CGO 的函式庫,用 Rust 重做一次後,對 Rust 又更熟悉;打鐵趁熱,趕緊記錄這次學習的過程與相關實作細節。
與 Go 相比,Rust 相對比較像 Scala。目前筆者主要以 Go 開發;之前因工作關係,用 Scala 開發推薦系統,所以筆者有 Go 與 Scala 實作經驗。這次學習筆記,就以 Go 與 Scala 為基礎,來記錄 Rust 的學習筆記。
- Rust 版本: 1.77.1
- 開發環境: Mac OS (arm64)
- 開發工具: VSCode
- 文件使用 Markdown Preview Enhanced 撰寫,請安裝完環境後再閱讀。
- Source on Github
- Rust 程式設計, 2/e (Programming Rust: Fast, Safe Systems Development, 2/e)
- The Rust Programming Language
- Rust by Example
- The Cargo Book
-
- 評估是否適合或需要學習 Rust
- 初步了解 Rust 運作方式
- 安裝開發環境
- 實作第一隻程式 - hello world
-
- Scalar Types
- Immutable and Mutable Variables
- Cast
- Overflow
- Scope, Shadowing and Freeze
-
- Tuple
- Array
- Vector
-
- Slice
- String and &str
-
- return and early return
- if-elseif-else
- loop
-
- Ownership, Clone, Copy and Move
- References and Borrowing
- Lifetime
-
- Struct
- Method
- Drive
- Ownership
- Some Mutable Field in Imutable Struct
-
- Enum
- Enum in Memory
- Define Method in Enum
- Option
-
- destructuring
- match https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
- if let
-
- traits
- Default
- Drop
- Clone
- Copy
- generic
- From / Into
- Operator Overloading
- traits
-
- Option
- Result
- Result and Main
- Early Return
-
- vector
- binary heap
- map
- set
-
- iterator
- clousure
-
- crates
- cargo
- cross compile
-
- unit test
- integration test
- test private function
-
- Box and Dereferencing
- Rc and Arc
- 19 Concurrency
- Arc and Mutex
- Send and Sync
- 20 Async
- clap: command line argument parser
- serde: serialization and deserialization
- json
- toml
- log and log4rs: logging
- Actix Web: web framework
- sqlx: execure sql
- Diesel: ORM Framework
- tokio: async framework
- async
- thread
- channel
- select!
- actor
- reqwest: http client
- websocket
- chrono: date and time
以下是我學 Rust 過程,記錄下來的一些資源,供大家參考。
- Awesome Rust
- clap
- serde-rs
- tokio.rs
- actix.rs
- redis-rs
- tonic
- gRPC-rs
- AutoCxx
- r2d2
- Burn
- Rocket
- Yew
- Diesel
- Official Onnx Runtime
- Ort
- Tch-rs
- Tensorflow Rust
- HuggingFace Tokenizers
- HuggingFace Text Generation Interface
- HuggingFace Candle
- PyO3 user guide
- Comprehensive Rust by Google
- Rust and WebAssembly
- Asynchronous Programming in Rust
- Rust Cookbook
- The bindgen User Guide
- The Rust Reference
- Rust语言圣经(Rust Course)
- The `wasm-bindgen` Guide
- The Rustonomicon
- CXX — safe interop between Rust and C++
- Learn Rust With Entirely Too Many Linked Lists
- Rust Design Patterns
- Rust语言中文社区
- Command Line Applications in Rust
- How to bind (Python + NumPy) with (Rust + Ndarray)
- Rust fact vs. fiction: 5 Insights from Google's Rust journey in 2022
- Comprehensive Rust (by Google)
- First Rust Code Shows Up in the Windows 11 Kernel
- Rust for Windows