SlideShare a Scribd company logo
Learn More
Rust Primer
Rust
What is Rust ?
Rust is a systems programming language with a focus on
safety, especially safe concurrency, supporting both
functional and imperative paradigms. Rust is syntactically
similar to C++, but its designers intend it to provide better
memory safety while still maintaining performance.
Rust was originally designed by Graydon Hoare at
Mozilla Research, with contributions from Dave Herman,
Brendan Eich, and many others. Rust won first place for
"most loved programming language" in the Stack Overflow
Developer Survey in 2016, 2017, and 2018
Why Rust ?
Empowering Everyone to build efficient and reliable software
● Performance
○ Rust is blazingly fast and memory-efficient: with no runtime or garbage collector, it
can power performance-critical services, run on embedded devices, and easily
integrate with other languages.
● Reliability
○ Rust’s rich type system and ownership model guarantee memory-safety and thread-
safety — and enable you to eliminate many classes of bugs at compile-time.
● Productivity
○ Rust has great documentation, a friendly compiler with useful error messages, and
top-notch tooling — an integrated package manager and build tool, smart multi-
editor support with auto-completion and type inspections, an auto-formatter, and
more.
Rust
Safety and Control
What is Safe
?
Lorem Ipsum comes from section Contrary to
popular belief, Lorem Ipsum is not simply random
text.
● Mutability
● Multiple references to same variable.
Memory Safety ?
● Use after Free (dangling pointers)
● Double Free.
● Null Pointer Dereference
Memory Safety ?
Use After Free
Memory Safety ?
Double Free
A double free in C, technically speaking, leads to undefined behavior. This means that the
program can behave completely arbitrarily and all bets are off about what happens.
Memory Safety ?
Null Pointer Dereference
A NULL pointer points to memory that doesn't exist. This may be address 0x00000000 or any
other implementation-defined value (as long as it can never be a real address). Dereferencing it
means trying to access whatever is pointed to by the pointer.
Memory Safety ?
Memory Safety ?
Mere pass Garbage Collector
hai ?
Memory Safety?
Garbage Collector
● 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.
Memory Safety?
Garbage Collector (Some Thoughts)
● Computer cannot know the exact timing that each object should be freed –
tracing.
● GC:
○ tracing : 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.
● No predictability – cannot used for real-time system
● Limited concurrency – global interpreter lock
Memory Safety?
Garbage Collector (Some Thoughts)
● No predictability
○ cannot used for real-time system
● Limited concurrency
○ global interpreter lock
● Larger code size
○ VM(or GC) must included
Memory Safety?
System Program
● Must be fast enough.
● Must have little runtime overhead.
● Must be Memory Safe
● Should be possible to have a direct memory access with safety
Garbage Collector can not provide it because of the overhead involved.
The Rust Way?
Compile time checks
Rust tries to achieve Safety and Control by pushing as many checks to the
compile time.
This is achieved mainly through the following concepts :
● Ownership.
● Borrowing
● Lifetimes
Ownership?
Ownership
Ownership
Ownership
Ownership
Ownership
Vijay does not have Maa
now she is with Ravi now.
Ownership
Ownership
Ownership
Ownership
Borrowing
Borrowing is about how can we have multiple references to the same object
● Achieved with &T operator
● Rust has both Mutable and Immutable variable (Immutable by default)
Borrowing
error: cannot borrow `v` as mutable because it is
also borrowed as immutable
v.push(34);
^
note: previous borrow of `v` occurs here; the
immutable borrow prevents
subsequent moves or mutable borrows of `v` until
the borrow ends
Borrowing
Rules
○ First, any borrow must last for a scope no greater than that of the owner.
○ Second, you may have one or the other of these two kinds of borrows,
but not both at the same time:
■ one or more references (&T) to a resource,
■ exactly one mutable reference (&mut T).
Borrowing
Rules
Borrowing
Rules
Lifetime
Lending out a reference to a resource that someone else owns can be
complicated. For example, imagine this set of operations:
1. I acquire a handle to some kind of resource.
2. I lend you a reference to the resource.
3. I decide I’m done with the resource, and deallocate it, while you still have
your reference.
4. You decide to use the resource.
Lifetime
The ownership system in Rust does this through a concept called lifetimes,
which describe the scope that a reference is valid for.
● Owner will always have power to deallocate or destroy a source.
● In Simple cases compiler is capable enough to identify the problem and give
you an error.
● In complex cases there is a way where you can provide hint to compiler
using ‘a keyword.
Lifetime
The ownership system in Rust does this through a concept called lifetimes,
which describe the scope that a reference is valid for.
● Owner will always have power to deallocate or destroy a source.
● In Simple cases compiler is capable enough to identify the problem and give
you an error.
● In complex cases there is a way where you can provide hint to compiler
using ‘a keyword.
Concurrency in
Rust
● Threads
● Message Passing
● Shared State using Mutex
● Extensible Concurrency - Send and Sync Traits
Cargo
● Cargo is the Rust package manager. Cargo downloads your Rust package’s
dependencies, compiles your packages, makes distributable packages, and
uploads them to crates.io, the Rust community’s package registry.
Cargo
Rustup
● Rustup is the rust tool chain installer.
● Easily switch between stable, beta and nightly
● Cross compiling is much simpler
● Easy to install and work like Node’s NVM or python pyEnv
Rustfmt
● Rustfmt automatically formats Rust code
● making it easier to read, write, and maintain.
● never debate spacing or brace position ever again.
Clippy
● Clippy helps developers of all experience levels write idiomatic code, and
enforce standards.
Cargo Doc
● Cargo’s doc builder makes it so no API ever goes undocumented. It’s
available locally through cargo doc, and online for public crates through
docs.rs.
IDE/Editors
Thank You!

More Related Content

PDF
Why rust?
PDF
An introduction to Rust: the modern programming language to develop safe and ...
PDF
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
PPTX
Introduction to Rust (Presentation).pptx
PDF
Introduction to rust: a low-level language with high-level abstractions
PDF
Introduction to Rust
PDF
Rust's Journey to Async/await
PDF
Deep drive into rust programming language
Why rust?
An introduction to Rust: the modern programming language to develop safe and ...
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Introduction to Rust (Presentation).pptx
Introduction to rust: a low-level language with high-level abstractions
Introduction to Rust
Rust's Journey to Async/await
Deep drive into rust programming language

What's hot (20)

PDF
Rust: Unlocking Systems Programming
PDF
The Rust Programming Language
PDF
Rust: Systems Programming for Everyone
PDF
Rust system programming language
PPT
Rust Programming Language
PPTX
Introduction to gRPC (Application) Presentation
PDF
The Rust Programming Language: an Overview
PPTX
Introduction to Rust language programming
PPTX
Rust vs C++
PDF
PDF
Performance Comparison of Mutex, RWLock and Atomic types in Rust
PPTX
Rust Intro
PPTX
Rust programming-language
ODP
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
PDF
OWASP SF - Reviewing Modern JavaScript Applications
PPTX
PDF
Embedded Rust on IoT devices
PDF
WAM: An embedded web runtime history for LG webOS and Automotive Grade Linux
PDF
Linux KVM環境におけるGPGPU活用最新動向
Rust: Unlocking Systems Programming
The Rust Programming Language
Rust: Systems Programming for Everyone
Rust system programming language
Rust Programming Language
Introduction to gRPC (Application) Presentation
The Rust Programming Language: an Overview
Introduction to Rust language programming
Rust vs C++
Performance Comparison of Mutex, RWLock and Atomic types in Rust
Rust Intro
Rust programming-language
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
OWASP SF - Reviewing Modern JavaScript Applications
Embedded Rust on IoT devices
WAM: An embedded web runtime history for LG webOS and Automotive Grade Linux
Linux KVM環境におけるGPGPU活用最新動向
Ad

Similar to Rust Primer (20)

PDF
The State of the Veil Framework
PDF
AV Evasion with the Veil Framework
PDF
Sistemas Distribuidos
PDF
Clojure: Programming self-optimizing webapps in Lisp
PDF
Distributed fun with etcd
PDF
Secure Developer Access at Decisiv
PDF
intro_to_rust.pptx_123456789012446789.pdf
PDF
Andrea Di Persio
PDF
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
PDF
Refactoring Applications for the XK7 and Future Hybrid Architectures
PDF
Why_safe_programming_matters_and_why_Rust_.pdf
PDF
Higher Level Malware
PDF
Blockchain and smart contracts, what they are and why you should really care ...
PDF
Pentester++
PPTX
Not my problem - Delegating responsibility to infrastructure
PDF
The Final Frontier, Automating Dynamic Security Testing
PDF
ContainerDays Boston 2016: "Hiding in Plain Sight: Managing Secrets in a Cont...
PDF
DEVIEW 2013
PDF
Code Camp NYC 2017 - How to deal with everything... | Chris Ozog - Codesushi
DOCX
Bsdtw17: theo de raadt: mitigations and other real security features
The State of the Veil Framework
AV Evasion with the Veil Framework
Sistemas Distribuidos
Clojure: Programming self-optimizing webapps in Lisp
Distributed fun with etcd
Secure Developer Access at Decisiv
intro_to_rust.pptx_123456789012446789.pdf
Andrea Di Persio
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Refactoring Applications for the XK7 and Future Hybrid Architectures
Why_safe_programming_matters_and_why_Rust_.pdf
Higher Level Malware
Blockchain and smart contracts, what they are and why you should really care ...
Pentester++
Not my problem - Delegating responsibility to infrastructure
The Final Frontier, Automating Dynamic Security Testing
ContainerDays Boston 2016: "Hiding in Plain Sight: Managing Secrets in a Cont...
DEVIEW 2013
Code Camp NYC 2017 - How to deal with everything... | Chris Ozog - Codesushi
Bsdtw17: theo de raadt: mitigations and other real security features
Ad

More from Knoldus Inc. (20)

PPTX
Angular Hydration Presentation (FrontEnd)
PPTX
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
PPTX
Self-Healing Test Automation Framework - Healenium
PPTX
Kanban Metrics Presentation (Project Management)
PPTX
Java 17 features and implementation.pptx
PPTX
Chaos Mesh Introducing Chaos in Kubernetes
PPTX
GraalVM - A Step Ahead of JVM Presentation
PPTX
Nomad by HashiCorp Presentation (DevOps)
PPTX
Nomad by HashiCorp Presentation (DevOps)
PPTX
DAPR - Distributed Application Runtime Presentation
PPTX
Introduction to Azure Virtual WAN Presentation
PPTX
Introduction to Argo Rollouts Presentation
PPTX
Intro to Azure Container App Presentation
PPTX
Insights Unveiled Test Reporting and Observability Excellence
PPTX
Introduction to Splunk Presentation (DevOps)
PPTX
Code Camp - Data Profiling and Quality Analysis Framework
PPTX
AWS: Messaging Services in AWS Presentation
PPTX
Amazon Cognito: A Primer on Authentication and Authorization
PPTX
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
PPTX
Managing State & HTTP Requests In Ionic.
Angular Hydration Presentation (FrontEnd)
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Self-Healing Test Automation Framework - Healenium
Kanban Metrics Presentation (Project Management)
Java 17 features and implementation.pptx
Chaos Mesh Introducing Chaos in Kubernetes
GraalVM - A Step Ahead of JVM Presentation
Nomad by HashiCorp Presentation (DevOps)
Nomad by HashiCorp Presentation (DevOps)
DAPR - Distributed Application Runtime Presentation
Introduction to Azure Virtual WAN Presentation
Introduction to Argo Rollouts Presentation
Intro to Azure Container App Presentation
Insights Unveiled Test Reporting and Observability Excellence
Introduction to Splunk Presentation (DevOps)
Code Camp - Data Profiling and Quality Analysis Framework
AWS: Messaging Services in AWS Presentation
Amazon Cognito: A Primer on Authentication and Authorization
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Managing State & HTTP Requests In Ionic.

Recently uploaded (20)

PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Download FL Studio Crack Latest version 2025 ?
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
assetexplorer- product-overview - presentation
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
iTop VPN Crack Latest Version Full Key 2025
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PDF
Nekopoi APK 2025 free lastest update
PPTX
history of c programming in notes for students .pptx
PPTX
Reimagine Home Health with the Power of Agentic AI​
Navsoft: AI-Powered Business Solutions & Custom Software Development
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Download FL Studio Crack Latest version 2025 ?
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Autodesk AutoCAD Crack Free Download 2025
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Design an Analysis of Algorithms I-SECS-1021-03
assetexplorer- product-overview - presentation
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Oracle Fusion HCM Cloud Demo for Beginners
Digital Systems & Binary Numbers (comprehensive )
iTop VPN Crack Latest Version Full Key 2025
Weekly report ppt - harsh dattuprasad patel.pptx
Nekopoi APK 2025 free lastest update
history of c programming in notes for students .pptx
Reimagine Home Health with the Power of Agentic AI​

Rust Primer

  • 2. Rust What is Rust ? Rust is a systems programming language with a focus on safety, especially safe concurrency, supporting both functional and imperative paradigms. Rust is syntactically similar to C++, but its designers intend it to provide better memory safety while still maintaining performance. Rust was originally designed by Graydon Hoare at Mozilla Research, with contributions from Dave Herman, Brendan Eich, and many others. Rust won first place for "most loved programming language" in the Stack Overflow Developer Survey in 2016, 2017, and 2018
  • 3. Why Rust ? Empowering Everyone to build efficient and reliable software ● Performance ○ Rust is blazingly fast and memory-efficient: with no runtime or garbage collector, it can power performance-critical services, run on embedded devices, and easily integrate with other languages. ● Reliability ○ Rust’s rich type system and ownership model guarantee memory-safety and thread- safety — and enable you to eliminate many classes of bugs at compile-time. ● Productivity ○ Rust has great documentation, a friendly compiler with useful error messages, and top-notch tooling — an integrated package manager and build tool, smart multi- editor support with auto-completion and type inspections, an auto-formatter, and more.
  • 5. What is Safe ? Lorem Ipsum comes from section Contrary to popular belief, Lorem Ipsum is not simply random text. ● Mutability ● Multiple references to same variable.
  • 6. Memory Safety ? ● Use after Free (dangling pointers) ● Double Free. ● Null Pointer Dereference
  • 7. Memory Safety ? Use After Free
  • 8. Memory Safety ? Double Free A double free in C, technically speaking, leads to undefined behavior. This means that the program can behave completely arbitrarily and all bets are off about what happens.
  • 9. Memory Safety ? Null Pointer Dereference A NULL pointer points to memory that doesn't exist. This may be address 0x00000000 or any other implementation-defined value (as long as it can never be a real address). Dereferencing it means trying to access whatever is pointed to by the pointer.
  • 12. Mere pass Garbage Collector hai ?
  • 13. Memory Safety? Garbage Collector ● 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.
  • 14. Memory Safety? Garbage Collector (Some Thoughts) ● Computer cannot know the exact timing that each object should be freed – tracing. ● GC: ○ tracing : 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. ● No predictability – cannot used for real-time system ● Limited concurrency – global interpreter lock
  • 15. Memory Safety? Garbage Collector (Some Thoughts) ● No predictability ○ cannot used for real-time system ● Limited concurrency ○ global interpreter lock ● Larger code size ○ VM(or GC) must included
  • 16. Memory Safety? System Program ● Must be fast enough. ● Must have little runtime overhead. ● Must be Memory Safe ● Should be possible to have a direct memory access with safety Garbage Collector can not provide it because of the overhead involved.
  • 17. The Rust Way? Compile time checks Rust tries to achieve Safety and Control by pushing as many checks to the compile time. This is achieved mainly through the following concepts : ● Ownership. ● Borrowing ● Lifetimes
  • 20. Ownership Ownership Vijay does not have Maa now she is with Ravi now.
  • 23. Borrowing Borrowing is about how can we have multiple references to the same object ● Achieved with &T operator ● Rust has both Mutable and Immutable variable (Immutable by default)
  • 24. Borrowing error: cannot borrow `v` as mutable because it is also borrowed as immutable v.push(34); ^ note: previous borrow of `v` occurs here; the immutable borrow prevents subsequent moves or mutable borrows of `v` until the borrow ends
  • 25. Borrowing Rules ○ First, any borrow must last for a scope no greater than that of the owner. ○ Second, you may have one or the other of these two kinds of borrows, but not both at the same time: ■ one or more references (&T) to a resource, ■ exactly one mutable reference (&mut T).
  • 28. Lifetime Lending out a reference to a resource that someone else owns can be complicated. For example, imagine this set of operations: 1. I acquire a handle to some kind of resource. 2. I lend you a reference to the resource. 3. I decide I’m done with the resource, and deallocate it, while you still have your reference. 4. You decide to use the resource.
  • 29. Lifetime The ownership system in Rust does this through a concept called lifetimes, which describe the scope that a reference is valid for. ● Owner will always have power to deallocate or destroy a source. ● In Simple cases compiler is capable enough to identify the problem and give you an error. ● In complex cases there is a way where you can provide hint to compiler using ‘a keyword.
  • 30. Lifetime The ownership system in Rust does this through a concept called lifetimes, which describe the scope that a reference is valid for. ● Owner will always have power to deallocate or destroy a source. ● In Simple cases compiler is capable enough to identify the problem and give you an error. ● In complex cases there is a way where you can provide hint to compiler using ‘a keyword.
  • 31. Concurrency in Rust ● Threads ● Message Passing ● Shared State using Mutex ● Extensible Concurrency - Send and Sync Traits
  • 32. Cargo ● Cargo is the Rust package manager. Cargo downloads your Rust package’s dependencies, compiles your packages, makes distributable packages, and uploads them to crates.io, the Rust community’s package registry.
  • 33. Cargo
  • 34. Rustup ● Rustup is the rust tool chain installer. ● Easily switch between stable, beta and nightly ● Cross compiling is much simpler ● Easy to install and work like Node’s NVM or python pyEnv
  • 35. Rustfmt ● Rustfmt automatically formats Rust code ● making it easier to read, write, and maintain. ● never debate spacing or brace position ever again.
  • 36. Clippy ● Clippy helps developers of all experience levels write idiomatic code, and enforce standards.
  • 37. Cargo Doc ● Cargo’s doc builder makes it so no API ever goes undocumented. It’s available locally through cargo doc, and online for public crates through docs.rs.