SlideShare a Scribd company logo
Introduction to Rust
Brief introduction
• First Inventor: Graydon Hoare (about 8 years)
• Mozilla foundation(2009~)
• Trait-based OOP
• Zero-cost abstraction
• High concurrency support
• Memory safety by ownership and lifetime
concept
Problem: Memory Safety
• Use-after-free (dangling pointer)
• Double free
• Null pointer dereference
These kind of problems cause not only
software crash, but also security
vulnerabilities.
Use-after free
Simple and trivial case
Dangling pointer
&
Local variable is allocated in stack,
a temporal storage of function.
If you return a reference of local variable,
the address will be invalidated.
If these two functions are far away from each other,
this kind of bugs can be very hard to find.
Hard case:
Iterator invalidation
Can you see the problem?
Even a famous library
may betray you
If you do not know much
about the internals...
Garbage collection
• Java, Python, Ruby, C#, Scala, Go...
• Programmer creates objects. However,
the computer is responsible to remove
them.
• No explicit malloc and free.
– Therefore no mistake.
Is the world saved?
The real life is not that easy...
• Computer cannot know the exact timing
that each object should be freed.
– tracing GC:GC engine should track all objects
periodically.
– reference counting: every object has a
counter; the number of pointers referencing
itself.
• Both ways need more memory and CPU
power.
Garbage Collection
• No predictability
– cannot used for real-time system
• Limited concurrency
– global interpreter lock
• Larger code size
– VM(or GC) must included
System program
• Must be FAST.
• Must has runtime overhead as little as
possible.
• Must be memory SAFE.
• Should be possible to direct memory
access.
• GC cannot be used in such area!
Rust programming language
• Zero-cost abstraction
• Memory safety without garbage collection
• Super fast code generation
• C function compatibility (extern "C")
• Simpler syntax than C++
Basic: move sementic
http://is.gd/pZKiBw
Basic: mutability
http://is.gd/OQDszP
Benchmark
• http://benchmarksgame.alioth.debian.org/
u64q/rust.html
• Program written in Rust is as fast as that of C!
Reminder: iterator invalidation
Case study: Servo
• Mozilla's next-gen web browser engine
• Written in Rust
• Parallel layout, rendering, ... almost
everything
• "During the 2 years of development, we
have never experienced any memory-
related bugs like use-after-free or double
free."
- an engineer from Mozilla
Performance enhencement
http://is.gd/dEamuS
The ownership magic
v is an owner of the vector
x borrows the vector from v
now v cannot modify the vector
because it lent the ownership to x
remember this?
&
http://is.gd/3MTsSC
Lifetime
borrowed pointer
cannot outlives
the owner!!
Borrowing rules
• You cannot borrow mutable reference from immutable
object
• You can borrow immutable reference many times
• You cannot borrow more than one mutable reference
• There cannot exist a mutable reference and an
immutable one simultaneously
• The lifetime of a borrowed reference should be ended
before the owner object do
Rust Programming Language

More Related Content

PDF
Why rust?
PDF
An introduction to Rust: the modern programming language to develop safe and ...
PPTX
Introduction to Rust language programming
PDF
Deep drive into rust programming language
PDF
The Rust Programming Language: an Overview
PPTX
Rust programming-language
PDF
Introduction to Rust
Why rust?
An introduction to Rust: the modern programming language to develop safe and ...
Introduction to Rust language programming
Deep drive into rust programming language
The Rust Programming Language: an Overview
Rust programming-language
Introduction to Rust

What's hot (20)

PPTX
Rust vs C++
PDF
Rust system programming language
PDF
Rust: Unlocking Systems Programming
ODP
Rust Primer
PDF
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
PDF
Introduce to Rust-A Powerful System Language
PPTX
JavaScript Promises
PDF
Rust: Systems Programming for Everyone
PDF
An introduction to Google test framework
PDF
Ownership System in Rust
PDF
The Rust Programming Language
PDF
Go Lang Tutorial
PDF
Go language presentation
PDF
PPTX
clean code book summary - uncle bob - English version
ODP
Clean code
PDF
Golang
PPTX
Go Programming Language (Golang)
PPTX
Kali Linux
Rust vs C++
Rust system programming language
Rust: Unlocking Systems Programming
Rust Primer
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Introduce to Rust-A Powerful System Language
JavaScript Promises
Rust: Systems Programming for Everyone
An introduction to Google test framework
Ownership System in Rust
The Rust Programming Language
Go Lang Tutorial
Go language presentation
clean code book summary - uncle bob - English version
Clean code
Golang
Go Programming Language (Golang)
Kali Linux
Ad

Similar to Rust Programming Language (20)

PDF
Rust: Reach Further
PDF
Rust Workshop - NITC FOSSMEET 2017
PDF
Rust "Hot or Not" at Sioux
PDF
Le langage rust
PDF
Rust Intro @ Roma Rust meetup
PDF
Guaranteeing Memory Safety in Rust
PDF
Intro to Rust 2019
ODP
Introduction To Rust
PPTX
The Rust Programming Language vs The C Programming Language
PPTX
Rust Intro
PPTX
Briefly Rust
PDF
Introduction to Rust - Waterford Tech Meetup 2025
PDF
Rust: Reach Further (from QCon Sao Paolo 2018)
PDF
Rust All Hands Winter 2011
PDF
Introduction to the rust programming language
PPTX
Why Rust? by Edd Barrett (codeHarbour December 2019)
PDF
Rust and Eclipse
PDF
Intro to Rust from Applicative / NY Meetup
PDF
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
PPTX
Introduction to Rust - Admios ALTalk Nov 2018
Rust: Reach Further
Rust Workshop - NITC FOSSMEET 2017
Rust "Hot or Not" at Sioux
Le langage rust
Rust Intro @ Roma Rust meetup
Guaranteeing Memory Safety in Rust
Intro to Rust 2019
Introduction To Rust
The Rust Programming Language vs The C Programming Language
Rust Intro
Briefly Rust
Introduction to Rust - Waterford Tech Meetup 2025
Rust: Reach Further (from QCon Sao Paolo 2018)
Rust All Hands Winter 2011
Introduction to the rust programming language
Why Rust? by Edd Barrett (codeHarbour December 2019)
Rust and Eclipse
Intro to Rust from Applicative / NY Meetup
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Introduction to Rust - Admios ALTalk Nov 2018
Ad

Recently uploaded (20)

PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PPTX
Big Data Technologies - Introduction.pptx
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Cloud computing and distributed systems.
PDF
Electronic commerce courselecture one. Pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
Empathic Computing: Creating Shared Understanding
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
KodekX | Application Modernization Development
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
Big Data Technologies - Introduction.pptx
Chapter 2 Digital Image Fundamentals.pdf
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Cloud computing and distributed systems.
Electronic commerce courselecture one. Pdf
Review of recent advances in non-invasive hemoglobin estimation
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Reach Out and Touch Someone: Haptics and Empathic Computing
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
cuic standard and advanced reporting.pdf
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Empathic Computing: Creating Shared Understanding
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Spectral efficient network and resource selection model in 5G networks
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development

Rust Programming Language