# Rust
知識點圖
良好記憶方式
Rust 常見問答
https://rustcc.cn/article?id=4a6054b8-f846-4ef3-8c7b-6c60664ab2b0
[TOC]
孤兒規則
```
Trait Struct
Ok 本地類型 and 本地類型
Ok 遠端類型 and 本地類型
Ok 本地類型 and 遠端類型
Error 遠端類型 and 遠端類型
```
Box、Fn、FnMut、FnOnes、Sized,都有#[fundamental] 可逃離孤兒規則
```rust
struct Int(i32);
trait Add<i32> for Int{
type Output = i32;
fn add(&self, other:i32) -> Self::Output{
self.0 + other
}
}
// Int(i32) 本地類型
// Option<Int> 遠端類型
// Add<i32> 遠端類型
// 所以不能實現
//trait Add<i32> for Option<Int>{
// type Output = i32;
// fn add(self, other:i32) -> i32{
// ...
// }
//}
// Int(i32) 本地類型
// Box<Int> 本地類型 因為Box常用所以有加入編譯器標示 #[fundamental]
// Add<i32> 遠端類型
// OK
trait Add<i32> for Box<Int>{
fn add(self, other:i32) -> i32{
self.0 + other
}
}
```
## 常用標誌
可自訂的標示屬性
```rust
// 该属性用于隐藏对未使用代码的警告。
#![allow(dead_code)]
```
標示屬性
```rust
// 跳離孤兒規則
#[fundamental]
```
## 文檔
Rust 官方推薦指南
https://www.rust-lang.org/learn
Rust Rust示例(官方)
https://doc.rust-lang.org/stable/rust-by-example/
Rust Rust示例(非官方中文版)
https://rustwiki.org/zh-CN/rust-by-example/
Rust 版本指南 2015 -> 2018
https://doc.rust-lang.org/stable/edition-guide/
中文
https://rustwiki.org/zh-CN/edition-guide/rust-2018/ownership-and-lifetimes/the-anonymous-lifetime.html
Rust RFC 歷史活動
https://rust-lang.github.io/rfcs/
Rust 各種語法範例
https://cheats.rs/
Rusr 部落格(經常提新版的發行功能)
https://blog.rust-lang.org/
Rust 實踐指南
https://rust-guide.budshome.com/index.html
Rust 使用鍊表學習
https://rust-unofficial.github.io/too-many-lists/
Rust 烹飪
https://rust-lang-nursery.github.io/rust-cookbook/
Rust 很棒的庫
https://github.com/rust-unofficial/awesome-rust
Rust 三方基礎學習筆記
https://skyao.io/learning-rust/docs.html
Rust 三方標準庫學習筆記
https://skyao.io/learning-rust/std.html
Rust 錯誤大全
https://doc.rust-lang.org/error-index.html
Rust 性能改善
https://nnethercote.github.io/perf-book/title-page.html
Rust async
https://rust-lang.github.io/async-book/
中文
https://rust-lang.github.io/async-book/
Rust 宏小書中文版
https://zjp-cn.github.io/tlborm/introduction.html
---
Rust 參考 單純講解各個語法的用法和細節,如編譯棄選項等等。針對該語法主題進行探討,如 struct 的語法等
https://doc.rust-lang.org/reference/introduction.html
Rust 編譯器文檔
https://rustc-dev-guide.rust-lang.org/
Rust rustc 編譯命令 平台支持h詳細資訊
https://doc.rust-lang.org/rustc/index.html
Rust rustup 工具練
https://rust-lang.github.io/rustup/index.html
Rust 補充文檔的存儲庫 其中也有 工具練的資料
https://forge.rust-lang.org/index.html
Rust 夜晚版標記不穩定新功能
https://doc.rust-lang.org/beta/unstable-book/the-unstable-book.html
---
Cargo 詳細資料
https://doc.rust-lang.org/cargo/index.html
## Rust 論壇
中文論壇
https://rustcc.cn/
英文論壇
https://users.rust-lang.org/latest
---
## 語言
## 語言慣例
**Borrow**
與AsRef 相似但比起Borrow 更重量級,Borrow 像是某個複雜體的借用,如一些複雜的智慧指針的實現。
**into_inner**
...
**`From` trait and `into()`**
https://rustwiki.org/zh-CN/rust-by-example/conversion/from_into.html
**`Debug` trait **
https://doc.rust-lang.org/std/fmt/trait.Debug.html
```htmlembedded=
<iframe
height=600 style="width: 100%;"
src="https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=8c0cbb2c0820b4ce1c8b78f59e8ca0cc" >
</iframe>
```
## 同步機制
https://doc.rust-lang.org/std/sync/index.html
**Arc**
Atomically Reference-Counted指針,可以在多線程環境中使用,以延長某些數據的生命週期,直到所有線程都使用完它。
https://doc.rust-lang.org/std/sync/struct.Arc.html
**Barrier**
確保多個線程在繼續執行之前將相互等待到達程序中的某個點。
https://doc.rust-lang.org/std/sync/struct.Barrier.html
**Condvar**
條件變量,提供在等待事件發生時阻塞線程的能力。
https://doc.rust-lang.org/std/sync/struct.Condvar.html
**mpsc channel**
多生產者單消費者隊列,用於基於消息的通信。可以提供輕量級的線程間同步機制,代價是一些額外的內存。
https://doc.rust-lang.org/std/sync/mpsc/index.html
**Mutex**
互斥機制,保證一次最多只有一個線程可以訪問一些數據。
https://doc.rust-lang.org/std/sync/struct.Mutex.html
**Once**
用於全局變量的線程安全、一次性初始化。
https://doc.rust-lang.org/std/sync/struct.Once.html
**RwLock**
提供了一種互斥機制,允許同時有多個讀取者,而一次只允許一個寫入者。在某些情況下,這可能比互斥鎖更有效。
https://doc.rust-lang.org/std/sync/struct.RwLock.html
## 好用程式庫
### Rayon
### Tokio
### tokio_rayon
### Rocket
https://github.com/SergioBenitez/Rocket/discussions/1781
https://github.com/SergioBenitez/Rocket/issues/714
## 好用線上編譯
https://replit.com
https://play.rust-lang.org
## Rust 設計模式
https://rust-unofficial.github.io/patterns/
https://rust-unofficial.github.io/patterns/anti_patterns/index.html
## Rust 中文月刊(精選)
https://rustmagazine.github.io/rust_magazine_2021/
未來實現 GAT
```rust
pub trait StreamingIterator {
type Item<'a>;
pub fn next(&'_ mut self) -> Option<Self::Item<'_>>;
}
```
{"metaMigratedAt":"2023-06-16T05:15:05.533Z","metaMigratedFrom":"YAML","title":"Rust","breaks":true,"robots":"noindex, nofollow","contributors":"[{\"id\":\"101340b2-4aaa-480a-9515-0e575cc6557c\",\"add\":5275,\"del\":798}]","description":"知識點圖"}