SlideShare a Scribd company logo
Introduction to The Rust
Programming Language
http://www.rust-lang.org
Nikolay Denev <nikolay.denev@williamhill.com>
History and Origins
‱ Started as a personal project by Graydon Hoare from Mozilla some
time around 2008
‱ Officially recognized as Mozilla sponsored project from 2009 and first
announced in 2010
‱ First Pre-Alpha release in January 2012
‱ First Stable release 1.0 in May 2015
‱ Currently at 1.12.1 (stable)
‱ Follows 6 week release cycle with Stable, Beta and Nightly branches.
‱ Mozilla’s experimental browser engine Servo is being written in Rust.
Goals and Features
‱ Designed as a systems programming language focusing on:
‱ Safety – Statically typed with extensive compile time validations.
‱ Speed – Compiled, allows low level access similar to C/C++.
‱ Concurrency – Built in support for threads, channels.
‱ Major features:
‱ Zero-cost abstractions (you pay only for what you use), Trait based generics
‱ Algebraic data types (enum), pattern matching.
‱ Move semantics / Borrow checks at compile time.
‱ Guaranteed memory safety and threading without data races.
‱ Type inference, Minimal Runtime (no garbage collector).
‱ Immutable bindings by default.
Generics, Zero cost abstractions
Pay only for what you use
‱ Trait based generics are monomorphised by default (static dispatch),
‱ Dynamic (vtable) dispatch possible using Trait objects.
struct Foo{ foo: String };
struct Bar{ bar: String };
trait FooBar {
fn fubar(&self) -> String;
}
impl FooBar for Foo {
fn fubar(&self) -> String {
self.foo.clone()
}
}
impl FooBar for Bar {
fn fubar(&self) -> String {
self.bar.clone()
}
}
Generics, Zero cost abstractions
Pay only for what you use
‱ Trait based generics are monomorphised by default (static dispatch),
‱ Dynamic (vtable) dispatch possible using Trait objects.
let foo = Foo { foo: “foo”.to_string() };
let bar = Bar { bar: “bar”.to_string() };
fn statically_dispatched_generic_function<T>(o: &T) -> String where T: FooBar {
o.foobar()
}
fn dynamically_dispatched_generic_function(o: &GetSome) -> String {
o.foobar()
}
assert_eq!(statically_dispatched_generic_function(foo, “foo”.to_string());
assert_eq!(statically_dispatched_generic_function(bar, “bar”.to_string());
assert_eq!(dynamically_dispatched_generic_function(foo, “foo”.to_string());
assert_eq!(dynamically_dispatched_generic_function(bar, “bar”.to_string());
Algebraic data types (enums)
Pattern matching and destructuring.
Enums in Rust represent a type with one of several possible variants,
with each variant optionally having associated data with it.
enum Fubar {
Foo(String),
Bar(String),
Fubar,
FooBar { id: String, count: u64 },
}
let x = Fubar::Foo(“foo”); // or let x = Fubar::Bar(“bar”); or 

match x {
Foo(s) => println!(“{}”, s), // or: Foo(s) | Bar(s), 1 
 3, Foo(_)
Bar(s) => println!(“{}”, s),
Fubar => println!(“FOOBAR!”),
FooBar(i, c) => println!(“Id: {}, count: {}”, i, c), // or: FooBar(i, c) if c > 5 => 

// _ => panic(“default”);
}
Move semantics a.k.a. the concept of ownership.
The Borrow Checker.
‱ Type and ownership/borrow checking at compile time ensures:
‱ Using a value typically means transfer of ownership.
‱ Only one mutable reference can exist.
‱ Or multiple immutable references can exist.
fn print(s: String) { println!(“{}”, s); }
let x = “something”.to_string();
print(x);
print(x);
error[E0382]: use of moved value: `x`
--> src/main.rs:4:7
3 | print(x);
| - value moved here
4 | print(x);
| ^ value used here after move
= note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy`
trait
Move semantics a.k.a. the concept of ownership.
The Borrow Checker.
‱ Type and ownership/borrow checking at compile time ensures:
‱ Using a value typically means transfer of ownership.
‱ Only one mutable reference can exist.
‱ Or multiple immutable references can exist.
or
fn print(s: &String) { println!(“{}”, s); }
let x = “something”.to_string();
print(&x);
print(&x);
fn print(s: String) { println!(“{}”, s); }
let x = “something”.to_string();
print(x.clone());
print(x.clone());
Move semantics a.k.a. the concept of ownership.
The Borrow Checker.
‱ Type and ownership/borrow checking at compile time ensures:
‱ Using a value typically means transfer of ownership.
‱ Only one mutable reference can exist.
‱ Or multiple immutable references can exist.
let x = String::from(“some”);
x.push_str(“thing”);
error: cannot borrow immutable local variable `x` as mutable
--> src/main.rs:1:1
|
1 | let x = String::from("some");
| - use `mut x` here to make mutable
2 | x.push_str("thing");
| ^ cannot borrow mutably
Move semantics a.k.a. the concept of ownership.
The Borrow Checker.
‱ Type and ownership/borrow checking at compile time ensures:
‱ Using a value typically means transfer of ownership.
‱ Only one mutable reference can exist.
‱ Or multiple immutable references.
let mut x = String::from(“some”);
x.push_str(“thing”);
assert_eq!(x, “something”.to_string());
Move semantics a.k.a. the concept of ownership.
The Borrow Checker and Lifetimes.
‱ Most of the time you don’t need to explicitly specify lifetimes,
however in some cases it is necessary:
struct Something<'a> {
id: &'a str,
}
impl<'a> Something<'a> {
fn id_ref(&'a self) -> &'a str {
self.id
}
}
fn main() {
// let s: &’static str = “static string”;
let s = Something { id: &String::from("something") };
assert_eq!("something", s.id_ref());
}
And much more
‱ String types (owned, vs slice).
‱ Stack allocation by default, or Box<>-ed for Heap allocation.
‱ Closures
‱ Cargo package manager, dependency and build tool
‱ Unsafe{}
‱ Concurrency: Send and Sync traits. Smart pointers like Arc<>,
Mutex<>, RwLock<>
‱ Async IO : mio, Futures
Additional resources
‱ https://www.rust-lang.org
‱ https://crates.io
‱ https://doc.rust-lang.org/stable/book
^^^ (previously known as Rust for Rubyists  )
‱ https://this-week-in-rust.org
‱ https://github.com/kud1ing/awesome-rust
‱ 
. much more 

Questions?

More Related Content

What's hot (20)

PDF
Introduction to Go programming language
Slawomir Dorzak
 
PDF
XAML/C# to HTML/JS
Michael Haberman
 
PDF
Kotlin Delegates: Reduce the boilerplate
Dmytro Zaitsev
 
PDF
Rust concurrency tutorial 2015 12-02
nikomatsakis
 
PPT
Python by ganesh kavhar
Savitribai Phule Pune University
 
ODP
Domain Specific Languages In Scala Duse3
Peter Maas
 
PDF
DConf 2016: Keynote by Walter Bright
Andrei Alexandrescu
 
PDF
Go Lang Tutorial
Wei-Ning Huang
 
PDF
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Ruslan Shevchenko
 
PDF
Pune Clojure Course Outline
Baishampayan Ghose
 
PDF
Building a Tagless Final DSL for WebGL
Luka Jacobowitz
 
PPT
Allura - an Open Source MongoDB Based Document Oriented SourceForge
Rick Copeland
 
PDF
C# for Java Developers
Jussi Pohjolainen
 
PDF
No excuses, switch to kotlin
Thijs Suijten
 
PDF
Introduction to Groovy (Serbian Developer Conference 2013)
Joachim Baumann
 
PDF
Csp scala wixmeetup2016
Ruslan Shevchenko
 
PDF
CodeFest 2010. Đ˜ĐœĐŸĐ·Đ”ĐŒŃ†Đ”ĐČ Đ˜. — Fantom. Cross-VM Language
CodeFest
 
PPTX
Introduction to Programming Bots
Dmitri Nesteruk
 
ODP
Hands on Session on Python
Sumit Raj
 
PPT
Fantom on the JVM Devoxx09 BOF
Dror Bereznitsky
 
Introduction to Go programming language
Slawomir Dorzak
 
XAML/C# to HTML/JS
Michael Haberman
 
Kotlin Delegates: Reduce the boilerplate
Dmytro Zaitsev
 
Rust concurrency tutorial 2015 12-02
nikomatsakis
 
Python by ganesh kavhar
Savitribai Phule Pune University
 
Domain Specific Languages In Scala Duse3
Peter Maas
 
DConf 2016: Keynote by Walter Bright
Andrei Alexandrescu
 
Go Lang Tutorial
Wei-Ning Huang
 
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Ruslan Shevchenko
 
Pune Clojure Course Outline
Baishampayan Ghose
 
Building a Tagless Final DSL for WebGL
Luka Jacobowitz
 
Allura - an Open Source MongoDB Based Document Oriented SourceForge
Rick Copeland
 
C# for Java Developers
Jussi Pohjolainen
 
No excuses, switch to kotlin
Thijs Suijten
 
Introduction to Groovy (Serbian Developer Conference 2013)
Joachim Baumann
 
Csp scala wixmeetup2016
Ruslan Shevchenko
 
CodeFest 2010. Đ˜ĐœĐŸĐ·Đ”ĐŒŃ†Đ”ĐČ Đ˜. — Fantom. Cross-VM Language
CodeFest
 
Introduction to Programming Bots
Dmitri Nesteruk
 
Hands on Session on Python
Sumit Raj
 
Fantom on the JVM Devoxx09 BOF
Dror Bereznitsky
 

Similar to Introduction to the rust programming language (20)

PDF
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Codemotion
 
PDF
Introduction to clojure
Abbas Raza
 
PDF
IOstreams hgjhsgfdjyggckhgckhjxfhbuvobunciu
akinbhattarai1
 
PDF
The Swift Compiler and Standard Library
Santosh Rajan
 
PDF
Intro to Rust 2019
Timothy Bess
 
PPT
Unit v
snehaarao19
 
PDF
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
Thoughtworks
 
PDF
Scala in practice - 3 years later
patforna
 
PPTX
Kotlin coroutines and spring framework
Sunghyouk Bae
 
PDF
Java I/O
Jussi Pohjolainen
 
PPTX
Code for Startup MVP (Ruby on Rails) Session 2
Henry S
 
PPT
Os Reindersfinal
oscon2007
 
PPT
Os Reindersfinal
oscon2007
 
PPT
Os Bubna
oscon2007
 
PPT
Apache Velocity
yesprakash
 
PPT
Apache Velocity
Bhavya Siddappa
 
PPT
json.ppt download for free for college project
AmitSharma397241
 
PDF
CSS: The Boring Bits
Peter Gasston
 
PPTX
gdscWorkShopJavascriptintroductions.pptx
sandeshshahapur
 
PPTX
Go from a PHP Perspective
Barry Jones
 
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Codemotion
 
Introduction to clojure
Abbas Raza
 
IOstreams hgjhsgfdjyggckhgckhjxfhbuvobunciu
akinbhattarai1
 
The Swift Compiler and Standard Library
Santosh Rajan
 
Intro to Rust 2019
Timothy Bess
 
Unit v
snehaarao19
 
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
Thoughtworks
 
Scala in practice - 3 years later
patforna
 
Kotlin coroutines and spring framework
Sunghyouk Bae
 
Java I/O
Jussi Pohjolainen
 
Code for Startup MVP (Ruby on Rails) Session 2
Henry S
 
Os Reindersfinal
oscon2007
 
Os Reindersfinal
oscon2007
 
Os Bubna
oscon2007
 
Apache Velocity
yesprakash
 
Apache Velocity
Bhavya Siddappa
 
json.ppt download for free for college project
AmitSharma397241
 
CSS: The Boring Bits
Peter Gasston
 
gdscWorkShopJavascriptintroductions.pptx
sandeshshahapur
 
Go from a PHP Perspective
Barry Jones
 
Ad

Recently uploaded (20)

PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Ad

Introduction to the rust programming language

  • 1. Introduction to The Rust Programming Language http://www.rust-lang.org Nikolay Denev <[email protected]>
  • 2. History and Origins ‱ Started as a personal project by Graydon Hoare from Mozilla some time around 2008 ‱ Officially recognized as Mozilla sponsored project from 2009 and first announced in 2010 ‱ First Pre-Alpha release in January 2012 ‱ First Stable release 1.0 in May 2015 ‱ Currently at 1.12.1 (stable) ‱ Follows 6 week release cycle with Stable, Beta and Nightly branches. ‱ Mozilla’s experimental browser engine Servo is being written in Rust.
  • 3. Goals and Features ‱ Designed as a systems programming language focusing on: ‱ Safety – Statically typed with extensive compile time validations. ‱ Speed – Compiled, allows low level access similar to C/C++. ‱ Concurrency – Built in support for threads, channels. ‱ Major features: ‱ Zero-cost abstractions (you pay only for what you use), Trait based generics ‱ Algebraic data types (enum), pattern matching. ‱ Move semantics / Borrow checks at compile time. ‱ Guaranteed memory safety and threading without data races. ‱ Type inference, Minimal Runtime (no garbage collector). ‱ Immutable bindings by default.
  • 4. Generics, Zero cost abstractions Pay only for what you use ‱ Trait based generics are monomorphised by default (static dispatch), ‱ Dynamic (vtable) dispatch possible using Trait objects. struct Foo{ foo: String }; struct Bar{ bar: String }; trait FooBar { fn fubar(&self) -> String; } impl FooBar for Foo { fn fubar(&self) -> String { self.foo.clone() } } impl FooBar for Bar { fn fubar(&self) -> String { self.bar.clone() } }
  • 5. Generics, Zero cost abstractions Pay only for what you use ‱ Trait based generics are monomorphised by default (static dispatch), ‱ Dynamic (vtable) dispatch possible using Trait objects. let foo = Foo { foo: “foo”.to_string() }; let bar = Bar { bar: “bar”.to_string() }; fn statically_dispatched_generic_function<T>(o: &T) -> String where T: FooBar { o.foobar() } fn dynamically_dispatched_generic_function(o: &GetSome) -> String { o.foobar() } assert_eq!(statically_dispatched_generic_function(foo, “foo”.to_string()); assert_eq!(statically_dispatched_generic_function(bar, “bar”.to_string()); assert_eq!(dynamically_dispatched_generic_function(foo, “foo”.to_string()); assert_eq!(dynamically_dispatched_generic_function(bar, “bar”.to_string());
  • 6. Algebraic data types (enums) Pattern matching and destructuring. Enums in Rust represent a type with one of several possible variants, with each variant optionally having associated data with it. enum Fubar { Foo(String), Bar(String), Fubar, FooBar { id: String, count: u64 }, } let x = Fubar::Foo(“foo”); // or let x = Fubar::Bar(“bar”); or 
 match x { Foo(s) => println!(“{}”, s), // or: Foo(s) | Bar(s), 1 
 3, Foo(_) Bar(s) => println!(“{}”, s), Fubar => println!(“FOOBAR!”), FooBar(i, c) => println!(“Id: {}, count: {}”, i, c), // or: FooBar(i, c) if c > 5 => 
 // _ => panic(“default”); }
  • 7. Move semantics a.k.a. the concept of ownership. The Borrow Checker. ‱ Type and ownership/borrow checking at compile time ensures: ‱ Using a value typically means transfer of ownership. ‱ Only one mutable reference can exist. ‱ Or multiple immutable references can exist. fn print(s: String) { println!(“{}”, s); } let x = “something”.to_string(); print(x); print(x); error[E0382]: use of moved value: `x` --> src/main.rs:4:7 3 | print(x); | - value moved here 4 | print(x); | ^ value used here after move = note: move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait
  • 8. Move semantics a.k.a. the concept of ownership. The Borrow Checker. ‱ Type and ownership/borrow checking at compile time ensures: ‱ Using a value typically means transfer of ownership. ‱ Only one mutable reference can exist. ‱ Or multiple immutable references can exist. or fn print(s: &String) { println!(“{}”, s); } let x = “something”.to_string(); print(&x); print(&x); fn print(s: String) { println!(“{}”, s); } let x = “something”.to_string(); print(x.clone()); print(x.clone());
  • 9. Move semantics a.k.a. the concept of ownership. The Borrow Checker. ‱ Type and ownership/borrow checking at compile time ensures: ‱ Using a value typically means transfer of ownership. ‱ Only one mutable reference can exist. ‱ Or multiple immutable references can exist. let x = String::from(“some”); x.push_str(“thing”); error: cannot borrow immutable local variable `x` as mutable --> src/main.rs:1:1 | 1 | let x = String::from("some"); | - use `mut x` here to make mutable 2 | x.push_str("thing"); | ^ cannot borrow mutably
  • 10. Move semantics a.k.a. the concept of ownership. The Borrow Checker. ‱ Type and ownership/borrow checking at compile time ensures: ‱ Using a value typically means transfer of ownership. ‱ Only one mutable reference can exist. ‱ Or multiple immutable references. let mut x = String::from(“some”); x.push_str(“thing”); assert_eq!(x, “something”.to_string());
  • 11. Move semantics a.k.a. the concept of ownership. The Borrow Checker and Lifetimes. ‱ Most of the time you don’t need to explicitly specify lifetimes, however in some cases it is necessary: struct Something<'a> { id: &'a str, } impl<'a> Something<'a> { fn id_ref(&'a self) -> &'a str { self.id } } fn main() { // let s: &’static str = “static string”; let s = Something { id: &String::from("something") }; assert_eq!("something", s.id_ref()); }
  • 12. And much more ‱ String types (owned, vs slice). ‱ Stack allocation by default, or Box<>-ed for Heap allocation. ‱ Closures ‱ Cargo package manager, dependency and build tool ‱ Unsafe{} ‱ Concurrency: Send and Sync traits. Smart pointers like Arc<>, Mutex<>, RwLock<> ‱ Async IO : mio, Futures
  • 13. Additional resources ‱ https://www.rust-lang.org ‱ https://crates.io ‱ https://doc.rust-lang.org/stable/book ^^^ (previously known as Rust for Rubyists  ) ‱ https://this-week-in-rust.org ‱ https://github.com/kud1ing/awesome-rust ‱ 
. much more