4. Agenda
• Mozilla in the Philippines
• Installing Rust
• Hello World, the Rust way
• Intro to Cargo
• IDE Support
• Variables & Constants
• Simple Arithmetic Functions
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.
26. 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.”
28. 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.
30. Rust vs Go
• Rust shares many of Go's qualities but
solves one major problem of Go:
• Go doesn't automatically share information between
different "channel" data structures
"race condition"
• A runaway situation in which a system can spiral
out of control because different processes are
working at odds with one another.
• Rust includes functions that eliminate
race conditions, making it a less-risky
language than Go for highly concurrent
programs.
32. Low-Level Programming
• (CS) a programming language that
provides little or no abstraction from a
computer's instruction set architecture
• commands or functions in the language
map closely to processor instructions.
• generally referred as either machine
code or assembly language.
• E.g. Assembly Language
33. High-Level Programming
• (CS) a programming language with strong
abstraction from the details of the
computer.
• Compared to low-level programming
languages
• may use natural language elements.
• may automate (or even hide entirely)
significant areas of computing systems
(e.g. memory management).
• E.g. COBOL, Fortran, LISP, ALGOL
36. 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).
40. Projects Using Rust
Magic Pocket
Dropbox's file storage system that powers their
Diskotech petabyte storage machines.
Servo
Mozilla's new parallel rendering engine developed
in collaboration with Samsung.
OpenDNS
Uses Rust in two of its components.
Redox OS
A microkernel operating system being developed
in Rust.
42. Installing Rust
• Installer for Windows, Mac OS X & Linux available via
https://www.rust-lang.org
• If you wish to run Rust on your local machine when
you’re offline.
• Rust Playground [https://play.rust-lang.org]
• If you are online, you may opt to use this one
instead.
• You may use ANY text editor to code in Rust.
• As a practice, please save your Rust code
using .rs file extension.
44. Function main()
• Every Rust program must have at least one (01)
function.
• Simplest possible function declaration is named as
“main”
fn main() {
}
• Functions can also take arguments
fn print_number(x:i32) {
println!(“x is: {}”, x);
}
48. Cargo
• A tool that allows Rust projects to declare their various
dependencies & ensure that you’ll always get a
repeatable build.
• Cargo does:
1. Introduces two (02) metadata files with various bits
of project information.
2. Fetches & builds your project’s dependencies.
3. Invokes rustc or another build tool with the correct
parameters to build your project.
4. Introduces conventions to make working with Rust
projects easier.
49. Cargo
• To start a new project with Cargo, we invoke in the
command line:
cargo new hello_world --bin
• Cargo will generate the following files & folders:
Cargo.toml [file]
src [folder]
main.rs [file]
• Acts as a manifest file
• Contains all of the metadata that Cargo needs to
compile your project.
51. TOML
• Tom’s Obvious, Minimal Language
(or some say, Tom’s Own Markup Language)
• Created by Tom Preston-Werner
• Aims to be a minimal configuration file format that's
easy to read due to obvious semantics.
• Designed to map unambiguously to a hash table.
• Should be easy to parse into data structures in a wide
variety of languages.
55. IDE Support
• Modern IDEs give developers a massive increase in
productivity.
• Several community projects have provided an excellent
start towards IDE support.
• Good IDE support requires a number of components:
• The compiler must be modified to operate in a
different mode.
• Must provide name & type information from the
compiler to the IDE.
• Must write plugins for the IDEs themselves so they
know what to do with Rust projects.
56. IDE Support
• Available IDE Plugins:
• Eclipse [https://github.com/RustDT/RustDT]
• Intellij IDEA [https://github.com/intellij-rust/intellij-rust]
• Visual Studio [https://github.com/PistonDevelopers/VisualRust]
• Editor Plugins:
• Atom [https://atom.io/packages/language-rust]
• Emacs [https://github.com/rust-lang/rust-mode]
• Sublime Text [https://packagecontrol.io/packages/Rust]
• Vim [https://github.com/rust-lang/rust.vim]
• Visual Studio Code
[https://github.com/saviorisdead/RustyCode]
57. More on IDE Support
https://www.rust-lang.org/ides.html
62. Mutability
• The ability to change something.
• Mutable variable binding.
• You’re allowed to change what the binding points to.
let x = 5;
x = 6; will result to an error!
• We can use the mut keyword:
let mut x = 5;
x = 6; no problem; no error!
63. Constants
• Aside from using variables, we can also declare
constants in Rust:
const PI:u8 = 3;
no fixed memory address
memory safety is NOT compromised
static X:i32 = 123;
66. Arithmetic Operators
• Rust DOES NOT support ++ and – used in other
programming languages.
• a = a+1; or
• a += 1;
• b = b-1; or
• b -= 1;
• You may also use the following in Rust
• *=
• /=
• %=
67. Arithmetic Operators
let mut a = 2+3*4;
println!(“Answer = {}.”, a);
let mut a = (2+3)*4;
println!(“Answer = {}.”, a);
68. Arithmetic Operators
let mut a = 10/3;
println!(“Answer = {}.”, a);
let mut a = 10%3;
println!(“Answer = {}.”, a);
let a=10;
println!(“Remainder of {} / {}
= {}”, a, 3, (a%3));
70. Arithmetic Operators (eg1)
fn main() {
let num1 = 20;
let num2 = 10;
println!(“The SUM of the numbers =
{}”, (num1 + num2));
println!(”The DIFFERENCE of the
numbers = {}”, (num1 – num2));
… and so on
71. Arithmetic Operators (eg2)
fn main() {
let num1 = 20;
let num2 = 10;
let sum = num1 + num2;
let dif = num1 – num2;
let pro = num1 * num2;
let quo = num1 / num2;
println!(“The SUM of the numbers =
{}”, sum);
… and so on
75. 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