Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
初探Rust.pdf
Search
Johnny Lin
February 08, 2023
Programming
140
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
初探Rust.pdf
介紹Rust程式語言,並講解核心概念: ownership。
Johnny Lin
February 08, 2023
More Decks by Johnny Lin
See All by Johnny Lin
Clean Code
johnny178
0
150
Other Decks in Programming
See All in Programming
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
590
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
Railsバージョンを4倍にした話
optim
0
350
Jetpack Compose Mechanisms
skydoves
3
820
すこし踏み込む CancellationToken
htkym
2
1.7k
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
気持ちぃ〜角丸 Squircle
ryu1013
0
310
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
32k
残高管理から台帳サービスへの進化
artoy
1
200
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
180
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
699
190k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
820
Are puppies a ranking factor?
jonoalderson
2
4.1k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
410
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Producing Creativity
orderedlist
PRO
348
41k
Into the Great Unknown - MozCon
thekraken
41
2.8k
Building the Perfect Custom Keyboard
takai
2
910
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
730
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
950
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Transcript
初探 Rust Johnny Lin @Anue Tech Sharing, 2023/02/08
Outline 什麼是 Rust ? 特色 應用 核心概念 Code Rules Recap
什麼是 Rust ? 由 Graydon Hoare 所設計,起 初只是一個 Side Project
,後來 他進入了 Mozilla ,Mozilla 開 始贊助並主導開發,最後也將 FireFox 的 C++ 的程式碼部 分,取代為成安全性較高的 Rust 。 讓每個人都能打造出可靠 又高效軟體的程式語言. “ “
特色 高效能 無垃圾回收機制(garbage collection) ,採用方式是 Ownership 可靠性 豐富的型別系統與所有權模型確保了記憶體以及執行緒的安全,在 編譯時期就能夠解決各式各樣的錯誤
特色
2016
2017
2018
2019
2020
2021
2022
應用
Deno 由 Node.JS 之父 Ryan Dahl 創建 基於 V8 引擎
建構 JS 與 TS 執行環境 解決 Node.js 的缺點
SWC 可擴展的基於 Rust 的前端構 建工具,核心功能相當於 Babel 目前為 Next.js 預設的 Compiler
,相較於 Babel 多 了 17 倍的速度
More and more... 命令列 WebAssembly 嵌入式系統
已採用的公司 Microsoft 將 Rust 集成到其大型 C/ C++ 代碼工程中 Facebook 使用
Rust 重寫了之前用 Python 編寫的源碼控制後端 Discord 從 Go 轉換到 Rust Figma 從 TypeScript 轉換到 Rust
核心概念
Ownership 所有權 在 Rust 中用來管理程式記憶體的一系列規則
比較 其他語言 垃圾回收機制,在程式執行時不斷尋找不再使用的記憶體 開發者必須親自分配和釋放記憶體 Rust 記憶體由所有權系統管理,編譯器會在編譯時加上一些規則檢查 不會在你程式的執行期間用到任何效能
Ownership 設計原因 解決追蹤哪個部分的程式用了哪些在 heap 上的資料 最佳化在 heap 上重複的資料 清除在 heap
上已經不用的資料
Memory
Stack 儲存 Value Types (Primitives) LIFO ( 後進先出) 有順序
Heap 儲存全域變數 不規律不可預測 動態記憶體空間 沒有 GC : C++ 需用 delete
語法來清除物件 有 GC :Java 的 Garbage collector 為了防止 memory leak 會自動釋 放 heap 上的記憶體空間
所有權規則 Rust 中每個數值都有個擁有者(owner ) 同時間只能有一個擁有者 當擁有者離開作用域時,數值就會被丟棄
Code in ownership
變數作用域 當 s 進入作用域時,它是有 效的 它持續被視為有效直到它離 開作用域為止 自動呼叫 drop 函式並清理該
變數在 Stack 上的資料
Copy y 在記憶體中複製了一整份完整 x 的資料
s2 name value ptr len 5 capacity 5 index value
0 h 1 e 2 l 3 l 4 o s1 name value ptr len 5 capacity 5 index value 0 h 1 e 2 l 3 l 4 o Move
s1 name value ptr len 5 capacity 5 index value
0 h 1 e 2 l 3 l 4 o s2 name value ptr len 5 capacity 5 Move Shadow Copy ?
s1 name value ptr len 5 capacity 5 index value
0 h 1 e 2 l 3 l 4 o s2 name value ptr len 5 capacity 5 Move Shadow Copy ? 造成雙重釋放(double free )!
s1 name value ptr len 5 capacity 5 index value
0 h 1 e 2 l 3 l 4 o s2 name value ptr len 5 capacity 5 Move
Ownership and Function
None
Rules Recap Rust 中每個數值都有個擁有者(owner ) 同時間只能有一個擁有者 當擁有者離開作用域時,數值就會被丟棄
Reference https://www.rust-lang.org/zh-TW https://ithelp.ithome.com.tw/users/20119807/ironman/2447 https://www.guru99.com/stack-vs-heap.html https://www.techug.com/post/famous-companies-that-use-rust-in- production-and-their-reasons-for-choosing-rust/
Thank you for listening