SlideShare a Scribd company logo
L l o y d M o o r e , P r e s i d e n t
L l o y d @ C y b e r D a t a - R o b o t i c s . c o m
w w w . C y b e r D a t a - R o b o t i c s . c o m
A Slice of Rust
Agenda:
We are going to look at a collection of topics
related to Rust programming that I have found
interesting over the past year developing several
projects.
In some cases I’ll compare and contrast to C++
and in others we’ll just look at the Rust topic.
Rust Development Environment:
Quite complete development “out of the box”:
 Rustup: Tool chain management program, including cross compilation tools
 Cargo: Top level build process management tool and package management
 Rustfmt: Rust code formatter run with “cargo fmt”
 Clippy: Rust linter – run with “cargo clippy”
 Documents: Built in, generate docs with “cargo rustdoc” or “cargo doc”
 Unit tests: Built in, run with “cargo test”
 Performance testing: Built in, run with “cargo bench”
 Rust language server: Editor support for many major editors
 Vim
 Emacs
 Sublime Text
 Atom
 Visual Studio Code
 IntelliJ / CLion
Rust Development Cycle
 “Feels” VERY different from a C++ development cycle
 Basic mechanics are the same: Edit, Compile, Run
 Compiler messages will give suggestions as well as
outright errors
 Can also include code snip-its
 Result is you feel more like you are having a “dialog”
with the compiler to edit and build the code
Coding Style Idiom Based
 When coding in Rust look for existing
patterns that already solve your problem.
 Similar to Design Patterns they are much
smaller patterns to solve specific problems
 This is typically referred to as “idomatic
code” and is more important in Rust than
other languages
 In some cases the compiler and/or linter
(clippy) will actually enforce an idomatic
pattern
Rust Language Evolution
 No formal language specification!
 The compiler is the specification
 Does place limits on where the language can be
used – cannot use for some projects requiring
DO-178x – will not be able to fully qualify the tool
chain!
 Allows for faster language iteration
 Language is less “regular” than C++
 Has “Editions” for language breaking changes,
increment every 3 years so far
 Has “stable” and “nightly” compiler versions
 “Stable” compiler updated every 6 weeks!
Crates.io – The package registry
 Packages are called “crates” in Rust
 Registry is integrated with cargo for both package
download and version management
 Appears to be a rather blurry line between a
“standard” library and what ends up in the registry
 Most packages have a MIT or Apache style license
 Not “curated” in any way, watch for:
 Documentation quality
 Number of recent downloads – some crates are
defacto standards, ie: serde and rand
 Last release and release cadance
Crates.io – The Website
Crates.io – Typical Package Entry
Std::time::Duration vs chrono::Duration
 Lloyd’s rule: If there are two similar things Lloyd
has a 90% chance of finding the wrong one!
 Std::time::Duration and chrono::Duration do
basically the same thing but are not compatible.
 Chrono is the more feature rich package, and
seems to be usually what you want.
 Frequently trips me up though, and error
messages can be more confusing in the context of
two packages with similar constructs.
Borrow Checker
 Likely the most loved and hated feature of Rust!
 Enforces compile time checks on variables:
 Initialized before use
 Not moved twice
 Not moved while “borrowed”
 Cannot be modified by more than one owner at a
time
 Etc….
 Fundamentally responsible for enforcing the safety
guarantees that make Rust unique.
 Will FORCE you to use different and better
patterns when writing code!
Borrow Checker : Modifying a list while
iterating
This is a rather contrived example but shows the behavior of the borrow checker.
This check is done at compile time with ZERO run time overhead!
The error message is also quite helpful – once you get used to it.
Match Statement Efficiency
 Match statement is much like C++ switch
 Also includes much more advanced pattern
matching.
 Herb Sutter has proposed a similar construct for C++:
 https://www.youtube.com/watch?v=raB_289NxBk
 So just how efficient is this statement?
 Note that Rust currently uses the LLVM back end
compiler and benefits from the optimizations there.
Match Statement Efficiency
This was an interesting case I just happened to try.
A constant result evaluates to basically no code even without specifying
optimization.
Match Statement Efficiency
Looking at the first part of the assembly code you can see a range check and
then the calculations resulting in an indirect jump at line 8.
You do in fact get a jump table in this case.
Match Statement Efficiency
A shorter case however (only 0...2) results in a branch chain.
Apparently the compiler decided this construct was more efficient in this case.
 Overall Rust can be just as efficient as C++.
 If you consider that additional compile time checks
can replace run time checks Rust can be more
efficient than C++ in some cases.
 Rust pays for this with increased build times,
however I’ve found this no worse than using C++
with a linter, such as clang-tidy.
 Construction of code which does not copy values
around is more difficult than in C++ owing to
borrow checker restrictions.
General Rust Efficiency
No Inheritance
 Rust promotes the composition pattern over
inheritance.
 In practice I’ve found this does result in
either:
 Duplicated code as each object must
contain what would be in a base class
 Need to use a different object model
 Need to use generic functions
 Need to use macros to generate a “family”
of objects
Rust Macros
 Macros are much more important and robust
than C++.
 Macro substitution happens in the abstract
syntax tree – NOT textual substitution!
 Parameters in macros can be restricted to
specific syntactic elements (expression,
block, etc.)
 With this can build domain specific
languages with Rust macros that intermix
with normal Rust code.
Rust Macros
 Two types of Rust Macros
 macro_rules
 Conceptually like enhanced C++ macros
 Procedural macros – allows for creating full
syntax extensions, and run code at compile
time.
 Conceptually allow you convert one AST
into another AST
 Have not had a chance to try these yet,
but conceptually very powerful.
Resources
 Rust Home Page
 https://www.rust-lang.org
 The Little Book of Rust Books
 https://lborb.github.io/book/title-page.html
 Rust Language Cheat Sheet
 https://cheats.rs/#cargo
Questions?

More Related Content

PPTX
Introduction to Rust (Presentation).pptx
PDF
Rust All Hands Winter 2011
PPTX
Rust vs C++
PDF
Intro to Rust 2019
PPTX
MozillaPH Rust Hack & Learn Session 1
PDF
The Rust Programming Language
ODP
Rust Primer
PPTX
Rust 101 (2017 edition)
Introduction to Rust (Presentation).pptx
Rust All Hands Winter 2011
Rust vs C++
Intro to Rust 2019
MozillaPH Rust Hack & Learn Session 1
The Rust Programming Language
Rust Primer
Rust 101 (2017 edition)

Similar to A Slice Of Rust - A quick look at the Rust programming language (20)

PDF
Embedded Rust
PDF
Rust in Action Systems programming concepts and techniques 1st Edition Tim Mc...
PDF
Rust and Eclipse
PPTX
Rust programming-language
PDF
Rust: Reach Further (from QCon Sao Paolo 2018)
PDF
Rusted Ruby
PDF
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
PDF
Rust: Systems Programming for Everyone
PDF
Interface Oxidation
PPTX
Rust Melbourne MeetUp - Rust Web Development
PPTX
Why Is Rust Gaining Traction In Recent Years?
PDF
Short intro to the Rust language
PPTX
Rustbridge
PDF
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
PPTX
From NodeJS to Rust
PPTX
PDF
Practical Rust 1x Cookbook Rustacean Team
PDF
Rust for professionals.pdf
PPTX
Rusty Python
Embedded Rust
Rust in Action Systems programming concepts and techniques 1st Edition Tim Mc...
Rust and Eclipse
Rust programming-language
Rust: Reach Further (from QCon Sao Paolo 2018)
Rusted Ruby
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Rust: Systems Programming for Everyone
Interface Oxidation
Rust Melbourne MeetUp - Rust Web Development
Why Is Rust Gaining Traction In Recent Years?
Short intro to the Rust language
Rustbridge
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
From NodeJS to Rust
Practical Rust 1x Cookbook Rustacean Team
Rust for professionals.pdf
Rusty Python
Ad

More from LloydMoore (15)

PPTX
Free / Open Source C++ Static Analysis Tools
PPTX
Chosing The Right Language for your project
PDF
Cuda Without a Phd - A practical guick start
PPTX
Less Magical Numbers - A coding standard proposal
PPTX
Debugging Intermittent Issues - A How To
PPTX
Successful Software Projects - What you need to consider
PPTX
What Have We Lost - A look at some historical techniques
PPTX
Raspberry pi robotics
PPTX
High Reliabilty Systems
PPTX
Real Time Debugging - What to do when a breakpoint just won't do
PPT
PSoC USB HID
PPT
Using PSoC Creator
PPT
Using the Cypress PSoC Processor
PPT
C for Microcontrollers
PPTX
Starting Raspberry Pi
Free / Open Source C++ Static Analysis Tools
Chosing The Right Language for your project
Cuda Without a Phd - A practical guick start
Less Magical Numbers - A coding standard proposal
Debugging Intermittent Issues - A How To
Successful Software Projects - What you need to consider
What Have We Lost - A look at some historical techniques
Raspberry pi robotics
High Reliabilty Systems
Real Time Debugging - What to do when a breakpoint just won't do
PSoC USB HID
Using PSoC Creator
Using the Cypress PSoC Processor
C for Microcontrollers
Starting Raspberry Pi
Ad

Recently uploaded (20)

PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Practice Questions on recent development part 1.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPT
Chapter 6 Design in software Engineeing.ppt
PPTX
Internship_Presentation_Final engineering.pptx
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Geodesy 1.pptx...............................................
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Lecture Notes Electrical Wiring System Components
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Practice Questions on recent development part 1.pptx
Internet of Things (IOT) - A guide to understanding
Foundation to blockchain - A guide to Blockchain Tech
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
OOP with Java - Java Introduction (Basics)
Structs to JSON How Go Powers REST APIs.pdf
Chapter 6 Design in software Engineeing.ppt
Internship_Presentation_Final engineering.pptx
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
CYBER-CRIMES AND SECURITY A guide to understanding
Geodesy 1.pptx...............................................
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Strings in CPP - Strings in C++ are sequences of characters used to store and...

A Slice Of Rust - A quick look at the Rust programming language

  • 1. L l o y d M o o r e , P r e s i d e n t L l o y d @ C y b e r D a t a - R o b o t i c s . c o m w w w . C y b e r D a t a - R o b o t i c s . c o m A Slice of Rust
  • 2. Agenda: We are going to look at a collection of topics related to Rust programming that I have found interesting over the past year developing several projects. In some cases I’ll compare and contrast to C++ and in others we’ll just look at the Rust topic.
  • 3. Rust Development Environment: Quite complete development “out of the box”:  Rustup: Tool chain management program, including cross compilation tools  Cargo: Top level build process management tool and package management  Rustfmt: Rust code formatter run with “cargo fmt”  Clippy: Rust linter – run with “cargo clippy”  Documents: Built in, generate docs with “cargo rustdoc” or “cargo doc”  Unit tests: Built in, run with “cargo test”  Performance testing: Built in, run with “cargo bench”  Rust language server: Editor support for many major editors  Vim  Emacs  Sublime Text  Atom  Visual Studio Code  IntelliJ / CLion
  • 4. Rust Development Cycle  “Feels” VERY different from a C++ development cycle  Basic mechanics are the same: Edit, Compile, Run  Compiler messages will give suggestions as well as outright errors  Can also include code snip-its  Result is you feel more like you are having a “dialog” with the compiler to edit and build the code
  • 5. Coding Style Idiom Based  When coding in Rust look for existing patterns that already solve your problem.  Similar to Design Patterns they are much smaller patterns to solve specific problems  This is typically referred to as “idomatic code” and is more important in Rust than other languages  In some cases the compiler and/or linter (clippy) will actually enforce an idomatic pattern
  • 6. Rust Language Evolution  No formal language specification!  The compiler is the specification  Does place limits on where the language can be used – cannot use for some projects requiring DO-178x – will not be able to fully qualify the tool chain!  Allows for faster language iteration  Language is less “regular” than C++  Has “Editions” for language breaking changes, increment every 3 years so far  Has “stable” and “nightly” compiler versions  “Stable” compiler updated every 6 weeks!
  • 7. Crates.io – The package registry  Packages are called “crates” in Rust  Registry is integrated with cargo for both package download and version management  Appears to be a rather blurry line between a “standard” library and what ends up in the registry  Most packages have a MIT or Apache style license  Not “curated” in any way, watch for:  Documentation quality  Number of recent downloads – some crates are defacto standards, ie: serde and rand  Last release and release cadance
  • 9. Crates.io – Typical Package Entry
  • 10. Std::time::Duration vs chrono::Duration  Lloyd’s rule: If there are two similar things Lloyd has a 90% chance of finding the wrong one!  Std::time::Duration and chrono::Duration do basically the same thing but are not compatible.  Chrono is the more feature rich package, and seems to be usually what you want.  Frequently trips me up though, and error messages can be more confusing in the context of two packages with similar constructs.
  • 11. Borrow Checker  Likely the most loved and hated feature of Rust!  Enforces compile time checks on variables:  Initialized before use  Not moved twice  Not moved while “borrowed”  Cannot be modified by more than one owner at a time  Etc….  Fundamentally responsible for enforcing the safety guarantees that make Rust unique.  Will FORCE you to use different and better patterns when writing code!
  • 12. Borrow Checker : Modifying a list while iterating This is a rather contrived example but shows the behavior of the borrow checker. This check is done at compile time with ZERO run time overhead! The error message is also quite helpful – once you get used to it.
  • 13. Match Statement Efficiency  Match statement is much like C++ switch  Also includes much more advanced pattern matching.  Herb Sutter has proposed a similar construct for C++:  https://www.youtube.com/watch?v=raB_289NxBk  So just how efficient is this statement?  Note that Rust currently uses the LLVM back end compiler and benefits from the optimizations there.
  • 14. Match Statement Efficiency This was an interesting case I just happened to try. A constant result evaluates to basically no code even without specifying optimization.
  • 15. Match Statement Efficiency Looking at the first part of the assembly code you can see a range check and then the calculations resulting in an indirect jump at line 8. You do in fact get a jump table in this case.
  • 16. Match Statement Efficiency A shorter case however (only 0...2) results in a branch chain. Apparently the compiler decided this construct was more efficient in this case.
  • 17.  Overall Rust can be just as efficient as C++.  If you consider that additional compile time checks can replace run time checks Rust can be more efficient than C++ in some cases.  Rust pays for this with increased build times, however I’ve found this no worse than using C++ with a linter, such as clang-tidy.  Construction of code which does not copy values around is more difficult than in C++ owing to borrow checker restrictions. General Rust Efficiency
  • 18. No Inheritance  Rust promotes the composition pattern over inheritance.  In practice I’ve found this does result in either:  Duplicated code as each object must contain what would be in a base class  Need to use a different object model  Need to use generic functions  Need to use macros to generate a “family” of objects
  • 19. Rust Macros  Macros are much more important and robust than C++.  Macro substitution happens in the abstract syntax tree – NOT textual substitution!  Parameters in macros can be restricted to specific syntactic elements (expression, block, etc.)  With this can build domain specific languages with Rust macros that intermix with normal Rust code.
  • 20. Rust Macros  Two types of Rust Macros  macro_rules  Conceptually like enhanced C++ macros  Procedural macros – allows for creating full syntax extensions, and run code at compile time.  Conceptually allow you convert one AST into another AST  Have not had a chance to try these yet, but conceptually very powerful.
  • 21. Resources  Rust Home Page  https://www.rust-lang.org  The Little Book of Rust Books  https://lborb.github.io/book/title-page.html  Rust Language Cheat Sheet  https://cheats.rs/#cargo