速查 / 與 C / Rust 對照
與 C / Rust 對照
語法對照表
| 變量 | let x = 1; | int x = 1; | let mut x = 1; |
| 函數 | fn f(a: i64) -> i64 | long f(long a) | fn f(a: i64) -> i64 |
| 結構體 | struct S { x: i64 } | struct S { long x; } | struct S { x: i64 } |
| 列舉帶數據 | enum E { A(i64), B } | 需手動 tag + union | enum E { A(i64), B } |
| 匹配 | match v { ... } | switch(僅整數) | match v { ... } |
| 字串 | str(NUL 結尾) | char* | String / &str |
| 泛型 | fn f<T>(x: T) | 宏 / void* | fn f<T>(x: T) |
| 借用 | &x / &mut x | 指針 | &x / &mut x |
| 錯誤處理 | Option / Result + match | errno / 返回值 | Result |
定位差異
| 記憶體安全 | 所有權 + 借用檢查 | 手動 | 所有權 + 借用檢查 |
| 上手 | 類 C、類型推斷、秒級編譯 | 需要手動管理一切 | 學習曲線陡 |
| 記憶體模型 | 所有權 + Arena 雙套 | 手動 malloc/free | 所有權 |
| 與 Python 互操作 | 一行 --pyext 導出 | 手寫擴展 | pyo3 |
| 編譯產物 | 獨立小 EXE / .pyd / .so | exe / .so | exe / .so |
一句話
Aero 取 Rust 的記憶體安全理念(所有權 + 借用檢查)和 C 的上手難度(類 C 語法、無複雜 trait 系統),再加一條 C/Rust 都沒有的捷徑:一行命令導出 Python 模塊。