KEMBAR78
Rustbridge | PPTX
Introduction to Rust
Programming language
By
Kent Marete
Twitter: @kentccs
github: maretekent
History of computers
• First "computer” word use was
recorded in 1613 - referring to a person
calculations, or computations.
• Tools –Abacus, Napier bones, slide rule,
pascaline, stepped reckoner etc.
• Difference Engine and Analytical Engine
- first mechanical computer
• Invented by Charles Babbage in 1822
and 1834
Charles Babbage
History of computers
• In 1840, Augusta Ada Byron suggests to Babbage that he use the
binary system.
• She writes programs for the Analytical Engine.
• She was the first programmer
Ada lovelace
First Programmers early 1930’s, 40’s ACE
Computer Generations
There are five generations
• First generation – 1946 – 1958 -- vacuum tubes for circuitry
and magnetic drums for memory. -solve one problem at a time
• Second generation – 1959 - 1964 -- Transistors replaced
vacuum tubes
• Third generation – 1965 - 1970 -- integrated circuit - silicon
chips
• Fourth generation – 1971 - today – microprocessor many ICs
• Fifth generation – Today to future -- Artificial Intelligence (AI)
Father of modern Computers
Machine code
• Instruction consist of operation code (op code) and Operand
• All are binary codes
• Machine code program consists of seq. of op code and operand are
stored in computer memory e.g. RAM
operand -part of a computer instruction that specifies data
Op code - part of a computer instruction that specifies
what operation
LD A, 01H
Opcode (load)
Register
Data (1)
Hex
Machine code
opcode
operand
MOV A, B
Assembly -- Mnemonics
High Level programming Languages
• Program - Set of instructions
• Programming - The art of creating programs
01010100
01101010
10001111
01111010
HLL – uses mathematical
symbols and english like syntax,
easy to learn, read.
Compiler,
Interpreters
and
assemblers
Low level language
High Level programming languages
Compiled languages - compiled code can be
executed directly by the computer's CPU.
the original program is translated into native
machine instructions, which are executed
directly by the hardware
Interpreted languages - translated at run-
time from any format to CPU machine
instructions
High Level programming languages
• Commands
• Syntax
• logic
HLL are portable and can run on multiple computers unlike
low level languages
Compiler - translates comp. program in HLL to machine code
Interpreter - translates comp. program in HLL to machine
code line by line
High Level programming languages
• Movie translation scenario - subtitles --- compiler
• Summit meetings interpretation of foreign lang --- interpreter
• Compiled lang: C, C++, Rust, Fotran, COBOL
• Interpreted lang: Python, Perl, Ruby
Systems programming is making of systems program.
Systems program are used to develop application programs
What is Rust?
• Rust is a systems programming language that runs blazingly fast, prevents
segfaults, and guarantees thread safety. (safety, concurrency, and speed)
• It’s a programming language founded by Mozilla research.
Rust
C++
Java
Python
Haskell
Scala
C
Perl
PHP
Javascript D
RubyC#
go
What Rust has to offer
• We can organize these languages in a linear spectrum
Control Safety
C C++ D Java
Python
Ruby
JS
Haskel
Scala
RUST
What Rust has built? / who is using Rust?
• Wasm – editors, browser game engines, https://www.figma.com
https://www.youtube.com/watch?v=ysFJHpS-O08
• Games - https://www.amethyst.rs/
-https://kripken.github.io/BananaBread/cube2/bb.html
• Block chain – etherium, exonum, crytape
• Friends of Rust - https://www.rust-lang.org/en-US/friends.html
• Jumo – cloud env manager
Table of content
• Rust, Cargo, Setup
• Syntax + Concepts mostly the same as other languages
• Syntax + Concepts particular to Rust
What is Cargo?
• Package manager
• Build tool
• Test runner
• Documentation generator
Setting up a Project
We're going to be making a binary project; the other option is a library.
cargo new will create a skeleton project setup for you.
1. cd to a directory where you like to store code
2. cargo new rustbridge
3. cd rustbridge
If you use version control, now would be a good time to commit.
Files created
• Cargo.toml: metadata about your project and its dependencies
• .gitignore: ignores compiled files built by Rust
• src/main.rs: where your Rust code goes
Cargo.toml
[package]
name = "rustbridge"
version = "0.1.0"
authors = [”Kent Marete <maretekent@gmail.com>"]
[dependencies]
src/main.rs
fn main() {
println!("Hello, world!");
}
Run it!
• cargo run
• Should print "Hello, world!"
• Now you have more files:
• target directory: all the built stuff
• Cargo.lock: locks your dependencies (we don't have any yet)
• Try printing out something else!
• Try printing out two things!
Syntax + Concepts mostly the same as
other languages
Comments
• Double slash at the beginning of a line (//)
• Try commenting out one of your lines printing!
• There are other kinds of comments but this is the most common
Variables
• let a:u8 = 123; // unsigned, immutable
• let mut b:i8 = 0; // mutable
• let mut c = 123456789; // it's an i32!
• let d:char = 'x'; // no type deco, single 32-bit unicode character
• let f:f64 = 2.5; // default float type
• let g = false; // true, g is of type boolean
• let name = "ashley";
Mutability
• let mut apples = 100;
• apples += 50;
• println!("I have {} apples", apples);
Type inference
• Every value has a type that the compiler has to know about.
• Most of the time, the compiler can figure it out.
• Sometimes it can't, and you'll get an error and need to add an
annotation.
• We could have written let age: i32 = 30;
• A place we must specify types is function definitions.
Functions
Conditionals if
Conditionals match
Arrays
Quick but Useful Tangent #1: println! formatting
• {} is called Display formatting; only on primitive types by default
• {:?} is called Debug formatting; more types have this by default
• Display is for end users, Debug is for... debugging
• Rust doesn't want to make assumptions
• My favorite: {:#?} = pretty debug
Quick but Useful Tangent #2: panic!
Panic stops your program with a message.
What happens in the last example if we try to access an element out of bounds of the array?
Vectors
• Vectors are dynamic arrays
Looping (and ranges)
Iterators
Enums
Control Flows
• While loop
loop
Control flows
• Match
• if
For loop
Syntax + Concepts particular to Rust
Result
Result
Result
Option
Slices
Slices Syntax
String Slices
Ownership
Transferring Ownership
References
Mutable References
Crates
http://crates.io
End

Rustbridge

  • 1.
    Introduction to Rust Programminglanguage By Kent Marete Twitter: @kentccs github: maretekent
  • 2.
    History of computers •First "computer” word use was recorded in 1613 - referring to a person calculations, or computations. • Tools –Abacus, Napier bones, slide rule, pascaline, stepped reckoner etc. • Difference Engine and Analytical Engine - first mechanical computer • Invented by Charles Babbage in 1822 and 1834 Charles Babbage
  • 3.
    History of computers •In 1840, Augusta Ada Byron suggests to Babbage that he use the binary system. • She writes programs for the Analytical Engine. • She was the first programmer Ada lovelace
  • 4.
    First Programmers early1930’s, 40’s ACE
  • 5.
    Computer Generations There arefive generations • First generation – 1946 – 1958 -- vacuum tubes for circuitry and magnetic drums for memory. -solve one problem at a time • Second generation – 1959 - 1964 -- Transistors replaced vacuum tubes • Third generation – 1965 - 1970 -- integrated circuit - silicon chips • Fourth generation – 1971 - today – microprocessor many ICs • Fifth generation – Today to future -- Artificial Intelligence (AI)
  • 6.
  • 7.
    Machine code • Instructionconsist of operation code (op code) and Operand • All are binary codes • Machine code program consists of seq. of op code and operand are stored in computer memory e.g. RAM operand -part of a computer instruction that specifies data Op code - part of a computer instruction that specifies what operation LD A, 01H Opcode (load) Register Data (1) Hex
  • 8.
    Machine code opcode operand MOV A,B Assembly -- Mnemonics
  • 9.
    High Level programmingLanguages • Program - Set of instructions • Programming - The art of creating programs 01010100 01101010 10001111 01111010 HLL – uses mathematical symbols and english like syntax, easy to learn, read. Compiler, Interpreters and assemblers Low level language
  • 10.
    High Level programminglanguages Compiled languages - compiled code can be executed directly by the computer's CPU. the original program is translated into native machine instructions, which are executed directly by the hardware Interpreted languages - translated at run- time from any format to CPU machine instructions
  • 11.
    High Level programminglanguages • Commands • Syntax • logic HLL are portable and can run on multiple computers unlike low level languages Compiler - translates comp. program in HLL to machine code Interpreter - translates comp. program in HLL to machine code line by line
  • 12.
    High Level programminglanguages • Movie translation scenario - subtitles --- compiler • Summit meetings interpretation of foreign lang --- interpreter • Compiled lang: C, C++, Rust, Fotran, COBOL • Interpreted lang: Python, Perl, Ruby Systems programming is making of systems program. Systems program are used to develop application programs
  • 13.
    What is Rust? •Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety. (safety, concurrency, and speed) • It’s a programming language founded by Mozilla research. Rust C++ Java Python Haskell Scala C Perl PHP Javascript D RubyC# go
  • 14.
    What Rust hasto offer • We can organize these languages in a linear spectrum Control Safety C C++ D Java Python Ruby JS Haskel Scala RUST
  • 15.
    What Rust hasbuilt? / who is using Rust? • Wasm – editors, browser game engines, https://www.figma.com https://www.youtube.com/watch?v=ysFJHpS-O08 • Games - https://www.amethyst.rs/ -https://kripken.github.io/BananaBread/cube2/bb.html • Block chain – etherium, exonum, crytape • Friends of Rust - https://www.rust-lang.org/en-US/friends.html • Jumo – cloud env manager
  • 16.
    Table of content •Rust, Cargo, Setup • Syntax + Concepts mostly the same as other languages • Syntax + Concepts particular to Rust
  • 17.
    What is Cargo? •Package manager • Build tool • Test runner • Documentation generator
  • 18.
    Setting up aProject We're going to be making a binary project; the other option is a library. cargo new will create a skeleton project setup for you. 1. cd to a directory where you like to store code 2. cargo new rustbridge 3. cd rustbridge If you use version control, now would be a good time to commit.
  • 19.
    Files created • Cargo.toml:metadata about your project and its dependencies • .gitignore: ignores compiled files built by Rust • src/main.rs: where your Rust code goes
  • 20.
    Cargo.toml [package] name = "rustbridge" version= "0.1.0" authors = [”Kent Marete <maretekent@gmail.com>"] [dependencies]
  • 21.
  • 22.
    Run it! • cargorun • Should print "Hello, world!" • Now you have more files: • target directory: all the built stuff • Cargo.lock: locks your dependencies (we don't have any yet) • Try printing out something else! • Try printing out two things!
  • 23.
    Syntax + Conceptsmostly the same as other languages
  • 24.
    Comments • Double slashat the beginning of a line (//) • Try commenting out one of your lines printing! • There are other kinds of comments but this is the most common
  • 26.
    Variables • let a:u8= 123; // unsigned, immutable • let mut b:i8 = 0; // mutable • let mut c = 123456789; // it's an i32! • let d:char = 'x'; // no type deco, single 32-bit unicode character • let f:f64 = 2.5; // default float type • let g = false; // true, g is of type boolean • let name = "ashley";
  • 27.
    Mutability • let mutapples = 100; • apples += 50; • println!("I have {} apples", apples);
  • 28.
    Type inference • Everyvalue has a type that the compiler has to know about. • Most of the time, the compiler can figure it out. • Sometimes it can't, and you'll get an error and need to add an annotation. • We could have written let age: i32 = 30; • A place we must specify types is function definitions.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
    Quick but UsefulTangent #1: println! formatting • {} is called Display formatting; only on primitive types by default • {:?} is called Debug formatting; more types have this by default • Display is for end users, Debug is for... debugging • Rust doesn't want to make assumptions • My favorite: {:#?} = pretty debug
  • 34.
    Quick but UsefulTangent #2: panic! Panic stops your program with a message. What happens in the last example if we try to access an element out of bounds of the array?
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
    Syntax + Conceptsparticular to Rust
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.

Editor's Notes

  • #14 It gives us control, we know what will run on our machines