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 - Ownership & Borrowing
Search
Arnaud
November 21, 2018
Programming
120
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rust - Ownership & Borrowing
Introduction to Rust ownership and borrowing concepts.
Arnaud
November 21, 2018
More Decks by Arnaud
See All by Arnaud
TLS 1.3 arrive!!! Et si on comprenait déjà ce que fait TLS 1.2 ?
alocquet
1
140
TLS 1.3 arrive!!! Et si on comprenait déjà ce que fait TLS 1.2 ?
alocquet
0
79
Serverless
alocquet
0
37
Other Decks in Programming
See All in Programming
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken
2
370
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.2k
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
160
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
4.2k
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
490
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
540
iOSDC2026登壇資料.pdf
riofujimon
0
190
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
690
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.5k
Are APIs Still Relevant in the AI Era?
soyuka
0
330
Verilogで学ぶCPU自作入門.pdf
uyuki234
8
3.6k
Featured
See All Featured
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
530
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Ruling the World: When Life Gets Gamed
codingconduct
0
370
WCS-LA-2024
lcolladotor
0
830
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
590
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
510
4 Signs Your Business is Dying
shpigford
187
23k
Documentation Writing (for coders)
carmenintech
77
5.5k
30 Presentation Tips
portentint
PRO
1
410
How STYLIGHT went responsive
nonsquared
100
6.3k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
410
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
Transcript
Rust Rust Onwership & Onwership & Borrowing Borrowing
Stack vs Heap Stack vs Heap Stack Stack fast automatically
desaclocated at scope end limited size pointers and primitives storage
Heap Heap slower manage memory allocation
Control vs Security Control vs Security Control : optimisation Security
: avoid memory allocation problems / memory leaks
Examples Examples allocating memory and never free it dangling pointers
keep a reference to freed memory have a reference to a moved variable (realloc) other problems...
Examples in C++ Examples in C++
Examples in C++ Examples in C++
Examples in C++ Examples in C++
Rust Rust manage desallocation at compile time avoid alias &
mutability at same time
Rust Rust Ownership Ownership
What happens when What happens when variable is copied variable
is copied primitives : stack copy others : "move" String example copy stack representation : pointer, length, capacity disable rst variable -> 'value used here after move'
Take Ownership Take Ownership copy variable into another variable pass
variable to function return variable from function
Keep Ownership after Keep Ownership after function call function call
send inputs as outputs
Clone Clone deep copy : stack + heap never done
automaticaly by rust done automaticaly by rust for Stack only data (@see Copy trait) : integers, boolean, oat, character, tuple of these types
Borrowing Borrowing Borrow a variable Keep ownership
: Reference : Reference
Borrowing : 2 ways Borrowing : 2 ways fn(val: &String)
no mutability any borrow as you want fn(val: &mut String) mutable other constraints
Mutable Reference Mutable Reference cannot make a mutable reference if
an immutable reference has been done
Mutable Reference Mutable Reference cannot make multiple mutables references avoid
data race
String case String case String : stored in the heap
&String : reference to a String &str : slice from a String &'static str : slice : stored in program
String case : &str String case : &str
world name value ptr len 5 index value 0 h
1 e 2 l 3 l 4 o 5 6 w 7 o 8 r 9 l 10 d s name value ptr len 11 capacity 11
String case String case as function parameter ? If we
don't need ownership -> &str fn example(value : &str) { println!(value); }
String case String case as function parameter ? If we
need owership -> String fn example($self, value : String) { self.value = value; }
String case String case &str : if the variable must
be used outside my struct/fn &str : if the variable should be large : avoid deep copy
Useful traits Useful traits Box : store data on the
heap Deref : &String -> &str Rc : data owned by multiple variable Mutex Into Cow
References References 2014 : Memory Safety in Rust : Intro
: String vs &str : https://www.youtube.com/watch? v=WQbg6ZMQJvQ http://intorust.com/ https://hermanradtke.com/2015/05/03/string-vs- str-in-rust-functions.html