SlideShare a Scribd company logo
Rust
Hack & Learn
Session #2
Robert “Bob” Reyes
05 Jul 2016
#MozillaPH
#RustPH
Check-in at Swarm &
Foursquare!
#MozillaPH
#RustPH
If you’re on social media, please use
our official hashtags for this event.
Agenda
• Mozilla in the Philippines
• Type Option in Rust
• Conditional Statements
• Loops
• Functions
• What to expect on Session 3?
Target Audience
• People with some background in
programming (any language).
• People with zero or near-zero knowledge
about Rust (Programming Language).
• People who wants to learn a new
programming language.
What is
Mozilla?
#MozillaPH
History of Mozilla
On 23 Feb 1998,
Netscape Communications Corp.
created a project called
Mozilla (Mosaic Killer + Godzilla).
Mozilla was launched 31 Mar 1998.
The
Mozilla Manifesto
Mozilla’s Mission
To ensure the Internet
is a global public
resource, open &
accessible to all.
Get involved …
Firefox Student
Ambassadors (FSA)
http://fsa.mozillaphilippines.org
Internship
at Mozilla
https://careers.mozilla.org/university/
Some stuff that we
are working on …
MozillaPH Rust Hack & Learn Session 2
#MozillaPH
MozillaPH Rust Hack & Learn Session 2
How to be part of
MozillaPH?
Areas of Contribution
 Helping Users
(Support)
 Testing & QA
 Coding
 Marketing
 Translation &
Localization
 Web Development
 Firefox Marketplace
 Add-ons
 Visual Design
 Documentation &
Writing
 Education
http://join.mozillaph.org
Join MozillaPH now!
http://join.mozillaph.org
Co-work from
MozSpaceMNL
http://mozspacemnl.org
MozillaPH Rust Hack & Learn Session 2
#MozillaPH
Let’s get to know
each other first.
What is your name?
From where are you?
What do you do?
Why are you here?
Where are the
MENTORS?
Please feel free to approach & ask
help from them 
What is
Rust?
What is Rust?
• Rust is a systems programming language
that runs blazingly fast, prevents
segfaults, & guarantees thread safety.
• Compiles to Native Code like C++ & D.
• Strength includes memory safety &
correctness (just like in C).
“Rust is a modern native-code language
with a focus on safety.”
Why
Rust?
Top 10 IoT Programming
Languages
1. C Language
2. C++
3. Python
4. Java
5. JavaScript
6. Rust
7. Go
8. Parasail
9. B#
10.Assembly
• No particular order.
• Based on popularity & following.
Mozilla &
Rust
Mozilla ❤️ Rust
• Rust grew out of a personal project by
Mozilla employee Graydon Hoare.
• Rust is sponsored by Mozilla Research
since 2009 (announced in 2010).
Type Option in
Rust
Type Option
• Type Option represents an optional value
• Every Option is either:
• Some  contains a value
or
• None  does not contain any value
Type Option
• Option types are very common in Rust code & can be
used as:
• Initial values
• Return values for functions that are not defined over
their entire input range (partial functions)
• Return value for otherwise reporting simple errors,
where None is returned on error
• Optional struct fields
• Struct fields that can be loaned or "taken" Optional
function arguments
• Nullable pointers
• Swapping things out of difficult situations
Conditionals in
Rust
If/Else Statement
If/Else Statement
• if-else in Rust is similar to other languages.
• However, the boolean condition doesn't need to be
surrounded by parentheses, &
• Each condition is followed by a block.
• if-else conditionals are expressions  all branches
must return the same type.
[Samples] If/Else
fn main() {
let n = 5;
if n < 0 {
println!(“{} is negative”, n);
} else if n > 0 {
println!(“{} is positive”, n);
} else {
println!(“{} is zero”, n);
}
}
[Samples] If/Else
 Add to the end of the previous example
let big_n =
if n < 10 && n > -10 {
println!(“and is a small number,
increase ten-fold”);
10 * n
} else {
println!(“and is a big number, reduce
by two”);
n / 2
};
println!(“{} -> {}”, n, big_n);
}
Loops in
Rust
Loop in Rust
• Rust provides a loop keyword to indicate an infinite
loop.
• The break statement can be used to exit a loop at
anytime,
• The continue statement can be used to skip the rest
of the iteration & start a new one.
[Samples] Loop
fn main() {
let mut count = 0u32;
println!(“Let’s count until infinity!”);
loop {
count +=1;
if count == 3 {
println!(“three”);
continue;
}
println!(“{}”, count);
if count == 5 {
println!(“OK, that’s enough!”);
break;
} } }
Nesting &
Labels
Nesting & Labels
• It is possible to break or continue outer loops when
dealing with nested loops.
• In these cases
• the loops must be annotated with some 'label
and
• the label must be passed to the break/continue
statement.
[Samples] Nesting & Labels
fn main() {
‘outer: loop {
println!(“Entered the outer loop”);
‘inner: loop {
println!(“Entered the inner
loop”);
break ‘outer;
}
println!(“This point will never be
reached”);
}
println!(“Exited the outer loop”);
}
While
Statement
While Statement
• The while keyword can be used to loop until a
condition is met.
• while loops are the correct choice when you’re not
sure how many times you need to loop.
[Samples] While Statement
fn main() {
let mut n = 1;
while n < 101 {
if n % 15 == 0 {
println!(“fizzbuzz”);
} else if n % 3 == 0 {
println!(“fizz”);
} else if n % 5 == 0 {
println!(“buzz”);
} else {
println!(“{}”, n);
}
n += 1;
} }
For & Range
Statement
For & Range Statement
• The for in construct can be used to iterate through
an Iterator.
• One of the easiest ways to create an iterator is to use
the range notation a..b.
• This will yield values from a (inclusive) to b (exclusive)
in steps (increment) of one.
[Samples] For & Range
fn main() {
for n in 1..101 {
if n % 15 == 0 {
println!(“fizzbuzz”);
} else if n % 3 == 0 {
println!(“fizz”);
} else if n % 5 == 0 {
println!(“buzz”);
} else {
println!(“{}”, n);
}
}
}
Match Statement
Match Statement
• Rust provides pattern matching via
the match keyword.
• Can be used like a switch statement in C.
[Samples] Match
fn main() {
let number = 13;
println!(“Tell me about {}”, number);
match number {
1 => println!(“one!”),
2 | 3 | 5 | 7 | 11 => println!(“prime”),
13…19 => println!(“a teen!”),
_ => println!(“not special”),
}
}
[Samples] Match
fn main() {
let boolean = true;
let binary = match boolean {
false => 0,
true => 1,
};
println!(“{} -> {}”, boolean, binary);
}
If Let
Statement
If Let Statement
• if let is a cleaner alternative to match statement.
• It allows various failure options to be specified.
[Samples] If Let
fn main() {
let number = Some(7);
let letter: Option<i32> = None;
let emoticon: Option <i32> = None;
if let Some(i) = number {
println!(“Matched {:?}!”, i);
} else {
println!(“Didn’t match a number. Let’s
go with a letter!”);
};
let i_like_letters = false;
<continued…>
[Samples] If Let
if let Some(i) = emoticon {
println!(“Matched {:?}!”, i);
} else if i_like_letters {
println!(“Didn’t matched a number. Let’s
go with a letter!”);
} else {
println!(“I don’t like letters. Let’s go
with an emoticon :)!”);
};
}
While Let
Statement
While Let Statement
• Similar to if let.
• while let can make awkward match sequences
more tolerable.
[Samples] While Let
fn main() {
let mut optional = Some(0);
while let Some(i) = optional {
if i > 9 {
println!(“Greater than 9, quit!”);
optional = None;
} else {
println!(“’i’ is ‘{:?}’.
Try again.”, i);
optional = Some(i + 1);
}
}
}
Functions in
Rust?
Functions in Rust
• Functions are declared using the fn keyword
• Arguments are type annotated, just like variables
• If the function returns a value, the return type must be
specified after an arrow ->
• The final expression in the function will be used as
return value.
• Alternatively, the return statement can be used to return
a value earlier from within the function, even from inside
loops or if’s.
[Samples] Functions
• Fizz Buzz Test
• "Write a program that prints the numbers from 1 to
100.
• But for multiples of three print “Fizz” instead of the
number
• For the multiples of five print “Buzz”.
• For numbers which are multiples of both three and
five print “FizzBuzz”."
[Samples] Functions
fn main() { fizzbuzz_to(100);
}
fn is_divisible_by(lhs: u32,
rhs: u32) -> bool {
if rhs == 0 {
return false;
}
lhs % rhs == 0
}
fn fizzbuzz(n: u32) -> () {
if is_divisible_by(n, 15)
{
println!(“fizzbuzz”);
} else if
is_divisible_by(n, 3) {
println!(“fizz”);
} else if
is_divisible_by(n, 5) {
println!(“buzz”);
} else { println!(“{}”,
n);
}
}
fn fizzbuzz_to(n: u32) {
for n in 1..n + 1 {
fizzbuzz(n);
}
}
Q&A
References
facebook.com/groups/rustph
https://rustph.slack.com
To request invite:
https://rustphslack.herokuapp.com
Reference Materials
• The Rust Programming Language Book
• https://doc.rust-lang.org/book/
• Rust by Example
• http://rustbyexample.com
• Rust User Forums
• https://users.rust-lang.org
• https://internals.rust-lang.org
What to expect
on Session #3?
Next: Session #3
• We need VOLUNTEERS to talk about:
• Rust Standard Library
• Vectors
• Strings
• Concurrency
• Error Handling
WANTED:
RustPH Mentors
WANTED: RustPH Mentors
• REQUIREMENTS:
 You love teaching other developers while learning
the Rust programming language.
• RustPH Mentors Meeting on Wed 13 Jul 2016 from
1900H to 2100H at MozSpaceMNL.
• MEETING AGENDA:
• Draw out some plans on how to attract more
developers in learning Rust.
• How to make developer journey in learning Rust a
fun yet learning experience.
Group Photo
Thank you!
Maraming salamat po!
http://www.mozillaphilippines.org
bob@mozillaph.org

Recommended

MozillaPH Rust Hack & Learn Session 1
MozillaPH Rust Hack & Learn Session 1
Robert 'Bob' Reyes
 
MozillaPH Rust Users Group Kick Off Meeting
MozillaPH Rust Users Group Kick Off Meeting
Robert 'Bob' Reyes
 
Connected Devices, MozVR & Firefox Developer Tools
Connected Devices, MozVR & Firefox Developer Tools
Robert 'Bob' Reyes
 
Introduction to Rust Programming Language
Introduction to Rust Programming Language
Robert 'Bob' Reyes
 
Rust Programming Language
Rust Programming Language
Jaeju Kim
 
Go for SysAdmins - LISA 2015
Go for SysAdmins - LISA 2015
Chris McEniry
 
OSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with Go
Chris McEniry
 
Introduction to python programming, Why Python?, Applications of Python
Introduction to python programming, Why Python?, Applications of Python
Pro Guide
 
On the Edge Systems Administration with Golang
On the Edge Systems Administration with Golang
Chris McEniry
 
Introduction to python
Introduction to python
Rajesh Rajamani
 
Python Intro
Python Intro
Tim Penhey
 
Python basic
Python basic
SOHIL SUNDARAM
 
GO programming language
GO programming language
tung vu
 
Intro to Python Workshop San Diego, CA (January 19, 2013)
Intro to Python Workshop San Diego, CA (January 19, 2013)
Kendall
 
Best Python Online Training with Live Project by Expert
Best Python Online Training with Live Project by Expert
QA TrainingHub
 
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Codemotion
 
ProjectTox: Free as in freedom Skype replacement
ProjectTox: Free as in freedom Skype replacement
Wei-Ning Huang
 
Intro to Python for Non-Programmers
Intro to Python for Non-Programmers
Ahmad Alhour
 
Writing Fast Code (JP) - PyCon JP 2015
Writing Fast Code (JP) - PyCon JP 2015
Younggun Kim
 
Ry pyconjp2015 karaoke
Ry pyconjp2015 karaoke
Renyuan Lyu
 
Introduction to-python
Introduction to-python
Aakashdata
 
Introduction to python programming
Introduction to python programming
Kiran Vadakkath
 
Python in real world.
Python in real world.
[email protected]
 
Beginning Python
Beginning Python
Ankur Shrivastava
 
Getting Started with Python
Getting Started with Python
Sankhya_Analytics
 
Python 101
Python 101
Ahmet SEĞMEN
 
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Juan-Manuel Gimeno
 
Welcome to Python
Welcome to Python
Elena Williams
 
First Ride on Rust
First Ride on Rust
David Evans
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011
Patrick Walton
 

More Related Content

What's hot (20)

On the Edge Systems Administration with Golang
On the Edge Systems Administration with Golang
Chris McEniry
 
Introduction to python
Introduction to python
Rajesh Rajamani
 
Python Intro
Python Intro
Tim Penhey
 
Python basic
Python basic
SOHIL SUNDARAM
 
GO programming language
GO programming language
tung vu
 
Intro to Python Workshop San Diego, CA (January 19, 2013)
Intro to Python Workshop San Diego, CA (January 19, 2013)
Kendall
 
Best Python Online Training with Live Project by Expert
Best Python Online Training with Live Project by Expert
QA TrainingHub
 
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Codemotion
 
ProjectTox: Free as in freedom Skype replacement
ProjectTox: Free as in freedom Skype replacement
Wei-Ning Huang
 
Intro to Python for Non-Programmers
Intro to Python for Non-Programmers
Ahmad Alhour
 
Writing Fast Code (JP) - PyCon JP 2015
Writing Fast Code (JP) - PyCon JP 2015
Younggun Kim
 
Ry pyconjp2015 karaoke
Ry pyconjp2015 karaoke
Renyuan Lyu
 
Introduction to-python
Introduction to-python
Aakashdata
 
Introduction to python programming
Introduction to python programming
Kiran Vadakkath
 
Python in real world.
Python in real world.
[email protected]
 
Beginning Python
Beginning Python
Ankur Shrivastava
 
Getting Started with Python
Getting Started with Python
Sankhya_Analytics
 
Python 101
Python 101
Ahmet SEĞMEN
 
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Juan-Manuel Gimeno
 
Welcome to Python
Welcome to Python
Elena Williams
 
On the Edge Systems Administration with Golang
On the Edge Systems Administration with Golang
Chris McEniry
 
GO programming language
GO programming language
tung vu
 
Intro to Python Workshop San Diego, CA (January 19, 2013)
Intro to Python Workshop San Diego, CA (January 19, 2013)
Kendall
 
Best Python Online Training with Live Project by Expert
Best Python Online Training with Live Project by Expert
QA TrainingHub
 
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Codemotion
 
ProjectTox: Free as in freedom Skype replacement
ProjectTox: Free as in freedom Skype replacement
Wei-Ning Huang
 
Intro to Python for Non-Programmers
Intro to Python for Non-Programmers
Ahmad Alhour
 
Writing Fast Code (JP) - PyCon JP 2015
Writing Fast Code (JP) - PyCon JP 2015
Younggun Kim
 
Ry pyconjp2015 karaoke
Ry pyconjp2015 karaoke
Renyuan Lyu
 
Introduction to-python
Introduction to-python
Aakashdata
 
Introduction to python programming
Introduction to python programming
Kiran Vadakkath
 
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Juan-Manuel Gimeno
 

Similar to MozillaPH Rust Hack & Learn Session 2 (20)

First Ride on Rust
First Ride on Rust
David Evans
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011
Patrick Walton
 
Download Complete The Rust Programming Language 2nd Edition Steve Klabnik PDF...
Download Complete The Rust Programming Language 2nd Edition Steve Klabnik PDF...
maggannawsad
 
The Rust Programming Language Steve Klabnik
The Rust Programming Language Steve Klabnik
willynnekane42
 
The Rust Programming Language 2nd Edition Steve Klabnik
The Rust Programming Language 2nd Edition Steve Klabnik
urbuuawara
 
Introduction To Rust part II Presentation
Introduction To Rust part II Presentation
Knoldus Inc.
 
The Rust Programming Language 2nd Edition Steve Klabnik
The Rust Programming Language 2nd Edition Steve Klabnik
onutaithakut25
 
The Rust Programming Language Second Edition 2 Converted Steve Klabnik
The Rust Programming Language Second Edition 2 Converted Steve Klabnik
nuovochady2s
 
The Rust Programming Language, Second Edition Steve Klabnik
The Rust Programming Language, Second Edition Steve Klabnik
killrnleiffi
 
The Rust Programming Language 2nd Edition Second Converted Steve Klabnik Caro...
The Rust Programming Language 2nd Edition Second Converted Steve Klabnik Caro...
cizekchingbj
 
Once Upon a Process
Once Upon a Process
David Evans
 
The Rust Programming Language Steve Klabnik
The Rust Programming Language Steve Klabnik
nmiriorola
 
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
Edureka!
 
Rust Intro
Rust Intro
Arthur Gavkaluk
 
Rustbridge
Rustbridge
kent marete
 
Rust for professionals.pdf
Rust for professionals.pdf
ssuser16d801
 
Rust in Action Systems programming concepts and techniques 1st Edition Tim Mc...
Rust in Action Systems programming concepts and techniques 1st Edition Tim Mc...
paaolablan
 
iRODS Rule Language Cheat Sheet
iRODS Rule Language Cheat Sheet
Samuel Lampa
 
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
apidays
 
Introduction to Rust language programming
Introduction to Rust language programming
Rodolfo Finochietti
 
First Ride on Rust
First Ride on Rust
David Evans
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011
Patrick Walton
 
Download Complete The Rust Programming Language 2nd Edition Steve Klabnik PDF...
Download Complete The Rust Programming Language 2nd Edition Steve Klabnik PDF...
maggannawsad
 
The Rust Programming Language Steve Klabnik
The Rust Programming Language Steve Klabnik
willynnekane42
 
The Rust Programming Language 2nd Edition Steve Klabnik
The Rust Programming Language 2nd Edition Steve Klabnik
urbuuawara
 
Introduction To Rust part II Presentation
Introduction To Rust part II Presentation
Knoldus Inc.
 
The Rust Programming Language 2nd Edition Steve Klabnik
The Rust Programming Language 2nd Edition Steve Klabnik
onutaithakut25
 
The Rust Programming Language Second Edition 2 Converted Steve Klabnik
The Rust Programming Language Second Edition 2 Converted Steve Klabnik
nuovochady2s
 
The Rust Programming Language, Second Edition Steve Klabnik
The Rust Programming Language, Second Edition Steve Klabnik
killrnleiffi
 
The Rust Programming Language 2nd Edition Second Converted Steve Klabnik Caro...
The Rust Programming Language 2nd Edition Second Converted Steve Klabnik Caro...
cizekchingbj
 
Once Upon a Process
Once Upon a Process
David Evans
 
The Rust Programming Language Steve Klabnik
The Rust Programming Language Steve Klabnik
nmiriorola
 
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
Edureka!
 
Rust for professionals.pdf
Rust for professionals.pdf
ssuser16d801
 
Rust in Action Systems programming concepts and techniques 1st Edition Tim Mc...
Rust in Action Systems programming concepts and techniques 1st Edition Tim Mc...
paaolablan
 
iRODS Rule Language Cheat Sheet
iRODS Rule Language Cheat Sheet
Samuel Lampa
 
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
apidays
 
Introduction to Rust language programming
Introduction to Rust language programming
Rodolfo Finochietti
 

More from Robert 'Bob' Reyes (20)

Localization at Mozilla
Localization at Mozilla
Robert 'Bob' Reyes
 
Firefox Dev Tools for WordPress Developers (WordCamp Iloilo 2019)
Firefox Dev Tools for WordPress Developers (WordCamp Iloilo 2019)
Robert 'Bob' Reyes
 
Build (Web)VR with A-Frame (COSCUP 2019 Taipei)
Build (Web)VR with A-Frame (COSCUP 2019 Taipei)
Robert 'Bob' Reyes
 
Challenges & Opportunities the Data Privacy Act Brings
Challenges & Opportunities the Data Privacy Act Brings
Robert 'Bob' Reyes
 
Rust 101 (2017 edition)
Rust 101 (2017 edition)
Robert 'Bob' Reyes
 
Building a Rust Community from Scratch (COSCUP 2017)
Building a Rust Community from Scratch (COSCUP 2017)
Robert 'Bob' Reyes
 
Mozilla + Rust at PCU Manila 02 DEC 2016
Mozilla + Rust at PCU Manila 02 DEC 2016
Robert 'Bob' Reyes
 
MozillaPH Localization in 2016
MozillaPH Localization in 2016
Robert 'Bob' Reyes
 
Mozilla & Connected Devices
Mozilla & Connected Devices
Robert 'Bob' Reyes
 
HTML 5 - The Future is Now
HTML 5 - The Future is Now
Robert 'Bob' Reyes
 
Getting started on MDN (Mozilla Developer Network)
Getting started on MDN (Mozilla Developer Network)
Robert 'Bob' Reyes
 
Mozilla & the Open Web
Mozilla & the Open Web
Robert 'Bob' Reyes
 
Firefox OS
Firefox OS
Robert 'Bob' Reyes
 
MozTour University of Perpetual Help System - Laguna (Binan)
MozTour University of Perpetual Help System - Laguna (Binan)
Robert 'Bob' Reyes
 
Firefox 101 (FSA Camp Philippines 2015)
Firefox 101 (FSA Camp Philippines 2015)
Robert 'Bob' Reyes
 
FOSSASIA 2015: Building an Open Source Community
FOSSASIA 2015: Building an Open Source Community
Robert 'Bob' Reyes
 
Welcome to MozSpaceMNL
Welcome to MozSpaceMNL
Robert 'Bob' Reyes
 
MozillaPH Trainers Training
MozillaPH Trainers Training
Robert 'Bob' Reyes
 
Mozilla Reps Program
Mozilla Reps Program
Robert 'Bob' Reyes
 
Women and the open web
Women and the open web
Robert 'Bob' Reyes
 
Firefox Dev Tools for WordPress Developers (WordCamp Iloilo 2019)
Firefox Dev Tools for WordPress Developers (WordCamp Iloilo 2019)
Robert 'Bob' Reyes
 
Build (Web)VR with A-Frame (COSCUP 2019 Taipei)
Build (Web)VR with A-Frame (COSCUP 2019 Taipei)
Robert 'Bob' Reyes
 
Challenges & Opportunities the Data Privacy Act Brings
Challenges & Opportunities the Data Privacy Act Brings
Robert 'Bob' Reyes
 
Building a Rust Community from Scratch (COSCUP 2017)
Building a Rust Community from Scratch (COSCUP 2017)
Robert 'Bob' Reyes
 
Mozilla + Rust at PCU Manila 02 DEC 2016
Mozilla + Rust at PCU Manila 02 DEC 2016
Robert 'Bob' Reyes
 
MozillaPH Localization in 2016
MozillaPH Localization in 2016
Robert 'Bob' Reyes
 
Getting started on MDN (Mozilla Developer Network)
Getting started on MDN (Mozilla Developer Network)
Robert 'Bob' Reyes
 
MozTour University of Perpetual Help System - Laguna (Binan)
MozTour University of Perpetual Help System - Laguna (Binan)
Robert 'Bob' Reyes
 
Firefox 101 (FSA Camp Philippines 2015)
Firefox 101 (FSA Camp Philippines 2015)
Robert 'Bob' Reyes
 
FOSSASIA 2015: Building an Open Source Community
FOSSASIA 2015: Building an Open Source Community
Robert 'Bob' Reyes
 

Recently uploaded (20)

Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 

MozillaPH Rust Hack & Learn Session 2

  • 1. Rust Hack & Learn Session #2 Robert “Bob” Reyes 05 Jul 2016 #MozillaPH #RustPH
  • 2. Check-in at Swarm & Foursquare!
  • 3. #MozillaPH #RustPH If you’re on social media, please use our official hashtags for this event.
  • 4. Agenda • Mozilla in the Philippines • Type Option in Rust • Conditional Statements • Loops • Functions • What to expect on Session 3?
  • 5. Target Audience • People with some background in programming (any language). • People with zero or near-zero knowledge about Rust (Programming Language). • People who wants to learn a new programming language.
  • 8. History of Mozilla On 23 Feb 1998, Netscape Communications Corp. created a project called Mozilla (Mosaic Killer + Godzilla). Mozilla was launched 31 Mar 1998.
  • 10. Mozilla’s Mission To ensure the Internet is a global public resource, open & accessible to all.
  • 14. Some stuff that we are working on …
  • 18. How to be part of MozillaPH?
  • 19. Areas of Contribution  Helping Users (Support)  Testing & QA  Coding  Marketing  Translation & Localization  Web Development  Firefox Marketplace  Add-ons  Visual Design  Documentation & Writing  Education http://join.mozillaph.org
  • 24. Let’s get to know each other first. What is your name? From where are you? What do you do? Why are you here?
  • 25. Where are the MENTORS? Please feel free to approach & ask help from them 
  • 27. What is Rust? • Rust is a systems programming language that runs blazingly fast, prevents segfaults, & guarantees thread safety. • Compiles to Native Code like C++ & D. • Strength includes memory safety & correctness (just like in C). “Rust is a modern native-code language with a focus on safety.”
  • 29. Top 10 IoT Programming Languages 1. C Language 2. C++ 3. Python 4. Java 5. JavaScript 6. Rust 7. Go 8. Parasail 9. B# 10.Assembly • No particular order. • Based on popularity & following.
  • 31. Mozilla ❤️ Rust • Rust grew out of a personal project by Mozilla employee Graydon Hoare. • Rust is sponsored by Mozilla Research since 2009 (announced in 2010).
  • 33. Type Option • Type Option represents an optional value • Every Option is either: • Some  contains a value or • None  does not contain any value
  • 34. Type Option • Option types are very common in Rust code & can be used as: • Initial values • Return values for functions that are not defined over their entire input range (partial functions) • Return value for otherwise reporting simple errors, where None is returned on error • Optional struct fields • Struct fields that can be loaned or "taken" Optional function arguments • Nullable pointers • Swapping things out of difficult situations
  • 37. If/Else Statement • if-else in Rust is similar to other languages. • However, the boolean condition doesn't need to be surrounded by parentheses, & • Each condition is followed by a block. • if-else conditionals are expressions  all branches must return the same type.
  • 38. [Samples] If/Else fn main() { let n = 5; if n < 0 { println!(“{} is negative”, n); } else if n > 0 { println!(“{} is positive”, n); } else { println!(“{} is zero”, n); } }
  • 39. [Samples] If/Else  Add to the end of the previous example let big_n = if n < 10 && n > -10 { println!(“and is a small number, increase ten-fold”); 10 * n } else { println!(“and is a big number, reduce by two”); n / 2 }; println!(“{} -> {}”, n, big_n); }
  • 41. Loop in Rust • Rust provides a loop keyword to indicate an infinite loop. • The break statement can be used to exit a loop at anytime, • The continue statement can be used to skip the rest of the iteration & start a new one.
  • 42. [Samples] Loop fn main() { let mut count = 0u32; println!(“Let’s count until infinity!”); loop { count +=1; if count == 3 { println!(“three”); continue; } println!(“{}”, count); if count == 5 { println!(“OK, that’s enough!”); break; } } }
  • 44. Nesting & Labels • It is possible to break or continue outer loops when dealing with nested loops. • In these cases • the loops must be annotated with some 'label and • the label must be passed to the break/continue statement.
  • 45. [Samples] Nesting & Labels fn main() { ‘outer: loop { println!(“Entered the outer loop”); ‘inner: loop { println!(“Entered the inner loop”); break ‘outer; } println!(“This point will never be reached”); } println!(“Exited the outer loop”); }
  • 47. While Statement • The while keyword can be used to loop until a condition is met. • while loops are the correct choice when you’re not sure how many times you need to loop.
  • 48. [Samples] While Statement fn main() { let mut n = 1; while n < 101 { if n % 15 == 0 { println!(“fizzbuzz”); } else if n % 3 == 0 { println!(“fizz”); } else if n % 5 == 0 { println!(“buzz”); } else { println!(“{}”, n); } n += 1; } }
  • 50. For & Range Statement • The for in construct can be used to iterate through an Iterator. • One of the easiest ways to create an iterator is to use the range notation a..b. • This will yield values from a (inclusive) to b (exclusive) in steps (increment) of one.
  • 51. [Samples] For & Range fn main() { for n in 1..101 { if n % 15 == 0 { println!(“fizzbuzz”); } else if n % 3 == 0 { println!(“fizz”); } else if n % 5 == 0 { println!(“buzz”); } else { println!(“{}”, n); } } }
  • 53. Match Statement • Rust provides pattern matching via the match keyword. • Can be used like a switch statement in C.
  • 54. [Samples] Match fn main() { let number = 13; println!(“Tell me about {}”, number); match number { 1 => println!(“one!”), 2 | 3 | 5 | 7 | 11 => println!(“prime”), 13…19 => println!(“a teen!”), _ => println!(“not special”), } }
  • 55. [Samples] Match fn main() { let boolean = true; let binary = match boolean { false => 0, true => 1, }; println!(“{} -> {}”, boolean, binary); }
  • 57. If Let Statement • if let is a cleaner alternative to match statement. • It allows various failure options to be specified.
  • 58. [Samples] If Let fn main() { let number = Some(7); let letter: Option<i32> = None; let emoticon: Option <i32> = None; if let Some(i) = number { println!(“Matched {:?}!”, i); } else { println!(“Didn’t match a number. Let’s go with a letter!”); }; let i_like_letters = false; <continued…>
  • 59. [Samples] If Let if let Some(i) = emoticon { println!(“Matched {:?}!”, i); } else if i_like_letters { println!(“Didn’t matched a number. Let’s go with a letter!”); } else { println!(“I don’t like letters. Let’s go with an emoticon :)!”); }; }
  • 61. While Let Statement • Similar to if let. • while let can make awkward match sequences more tolerable.
  • 62. [Samples] While Let fn main() { let mut optional = Some(0); while let Some(i) = optional { if i > 9 { println!(“Greater than 9, quit!”); optional = None; } else { println!(“’i’ is ‘{:?}’. Try again.”, i); optional = Some(i + 1); } } }
  • 64. Functions in Rust • Functions are declared using the fn keyword • Arguments are type annotated, just like variables • If the function returns a value, the return type must be specified after an arrow -> • The final expression in the function will be used as return value. • Alternatively, the return statement can be used to return a value earlier from within the function, even from inside loops or if’s.
  • 65. [Samples] Functions • Fizz Buzz Test • "Write a program that prints the numbers from 1 to 100. • But for multiples of three print “Fizz” instead of the number • For the multiples of five print “Buzz”. • For numbers which are multiples of both three and five print “FizzBuzz”."
  • 66. [Samples] Functions fn main() { fizzbuzz_to(100); } fn is_divisible_by(lhs: u32, rhs: u32) -> bool { if rhs == 0 { return false; } lhs % rhs == 0 } fn fizzbuzz(n: u32) -> () { if is_divisible_by(n, 15) { println!(“fizzbuzz”); } else if is_divisible_by(n, 3) { println!(“fizz”); } else if is_divisible_by(n, 5) { println!(“buzz”); } else { println!(“{}”, n); } } fn fizzbuzz_to(n: u32) { for n in 1..n + 1 { fizzbuzz(n); } }
  • 67. Q&A
  • 71. Reference Materials • The Rust Programming Language Book • https://doc.rust-lang.org/book/ • Rust by Example • http://rustbyexample.com • Rust User Forums • https://users.rust-lang.org • https://internals.rust-lang.org
  • 72. What to expect on Session #3?
  • 73. Next: Session #3 • We need VOLUNTEERS to talk about: • Rust Standard Library • Vectors • Strings • Concurrency • Error Handling
  • 75. WANTED: RustPH Mentors • REQUIREMENTS:  You love teaching other developers while learning the Rust programming language. • RustPH Mentors Meeting on Wed 13 Jul 2016 from 1900H to 2100H at MozSpaceMNL. • MEETING AGENDA: • Draw out some plans on how to attract more developers in learning Rust. • How to make developer journey in learning Rust a fun yet learning experience.
  • 77. Thank you! Maraming salamat po! http://www.mozillaphilippines.org [email protected]

Editor's Notes

  • #68: - IDE for Rust
  • #69: - IDE for Rust
  • #70: - IDE for Rust
  • #71: - IDE for Rust
  • #73: - IDE for Rust
  • #74: - image processing in rust - is rust OO
  • #75: - IDE for Rust
  • #76: - image processing in rust - is rust OO