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

More Related Content

What's hot (20)

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

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

PDF
Python Loop
Soba Arjun
 
PPTX
industry coding practice unit-2 ppt.pptx
LakshmiMarineni
 
PPT
Control structures pyhton
Prakash Jayaraman
 
PPTX
Loops in python.pptx/ introduction to loops in python
kinzaayaz464
 
PPTX
introduction to loops in python/python loops
kinzaayaz464
 
PPTX
Groovy Programming Language
Aniruddha Chakrabarti
 
PDF
Unit 1- Part-2-Control and Loop Statements.pdf
Harsha Patil
 
PPTX
Python_Loops.pptxpython loopspython loopspython loopspython loopspython loops...
RutviBaraiya
 
PPTX
Mastering Python lesson3b_for_loops
Ruth Marvin
 
PPTX
Dr.C S Prasanth-Physics ppt.pptx computer
kavitamittal18
 
PPTX
Loops in Python.pptx
Guru Nanak Dev University, Amritsar
 
PPTX
python ppt.pptx
ssuserd10678
 
PPTX
ForLoops.pptx
RabiyaZhexembayeva
 
PPTX
Python if_else_loop_Control_Flow_Statement
AbhishekGupta692777
 
PPTX
Presentation 2nd
Connex
 
PPT
name name2 n2.ppt
callroom
 
PPT
Ruby for Perl Programmers
amiable_indian
 
PPT
ppt2
callroom
 
PPT
name name2 n
callroom
 
PPT
name name2 n2
callroom
 
Python Loop
Soba Arjun
 
industry coding practice unit-2 ppt.pptx
LakshmiMarineni
 
Control structures pyhton
Prakash Jayaraman
 
Loops in python.pptx/ introduction to loops in python
kinzaayaz464
 
introduction to loops in python/python loops
kinzaayaz464
 
Groovy Programming Language
Aniruddha Chakrabarti
 
Unit 1- Part-2-Control and Loop Statements.pdf
Harsha Patil
 
Python_Loops.pptxpython loopspython loopspython loopspython loopspython loops...
RutviBaraiya
 
Mastering Python lesson3b_for_loops
Ruth Marvin
 
Dr.C S Prasanth-Physics ppt.pptx computer
kavitamittal18
 
python ppt.pptx
ssuserd10678
 
ForLoops.pptx
RabiyaZhexembayeva
 
Python if_else_loop_Control_Flow_Statement
AbhishekGupta692777
 
Presentation 2nd
Connex
 
name name2 n2.ppt
callroom
 
Ruby for Perl Programmers
amiable_indian
 
ppt2
callroom
 
name name2 n
callroom
 
name name2 n2
callroom
 

More from Robert 'Bob' Reyes (20)

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

Recently uploaded (20)

PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 

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