introduction to rust
TRANSCRIPT
![Page 1: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/1.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Introduction To Rust
“The type safety of Haskell, the concurrency of Erlang, and the speed of C++”
![Page 2: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/2.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
About
github.com/jeanCarloMachadotwitter.com/JeanCarloMachadjeancarlomachado.com.brcompufacil.com.br
![Page 3: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/3.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Rust
Generic multiparadigm system’s programming language.
Version 1.0 in May of 2015, 1.10 currently.
Platforms:▶ ARM▶ Apple▶ MIPS▶ PC▶ Raspberry PI▶ TIVA▶ Tessel 2▶ Others
![Page 4: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/4.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Rust
Generic multiparadigm system’s programming language.Version 1.0 in May of 2015, 1.10 currently.
Platforms:▶ ARM▶ Apple▶ MIPS▶ PC▶ Raspberry PI▶ TIVA▶ Tessel 2▶ Others
![Page 5: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/5.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Rust
Generic multiparadigm system’s programming language.Version 1.0 in May of 2015, 1.10 currently.
Platforms:▶ ARM▶ Apple▶ MIPS▶ PC▶ Raspberry PI▶ TIVA▶ Tessel 2▶ Others
![Page 6: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/6.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Who Built?
Mozilla Research team (2009)
▶ Graydon Hoare https://github.com/graydon▶ Brian Anderson https://github.com/brson▶ Patrick Walton https://github.com/pcwalton▶ Alex Crichton https://github.com/alexcrichton
![Page 7: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/7.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Built for
Patrick Walton: Rust should focus on the same domain as C++ does.
▶ Browser Engines▶ Games▶ IOT▶ OS’s
![Page 8: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/8.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Who Uses?
▶ Servo: Browser engine▶ Dropbox▶ Coursera▶ Skylight: New relic for rails▶ Redox: Unix based OS▶ Tikv: Distributed database▶ Many more
![Page 9: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/9.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
In the wild
Figure 1:who uses
![Page 10: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/10.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Interest
Figure 2:Interest
![Page 11: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/11.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Strengths
▶ Security▶ Performance▶ Fine grained control
![Page 12: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/12.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Weaknesses
▶ Fight the borrow checker▶ Huge syntax▶ Relatively new
![Page 13: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/13.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Rust vs the world
![Page 14: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/14.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Go
▶ fast compilation▶ simplicity▶ imperative foundations▶ higher level (Haskell,OCaml,C#,F#)
![Page 15: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/15.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Rust
▶ slow compilation▶ long list of features▶ functional foundations▶ lower level (C++,C,D)
![Page 16: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/16.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Figure 3:Servo performance
![Page 17: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/17.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Figure 4:Performance
![Page 18: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/18.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
rustc
▶ Written in Rust▶ Uses LLVM▶ MIR▶ Zero cost abstractions
![Page 19: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/19.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Syntax
![Page 20: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/20.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
fn fib(n: u64) -> u64 {match n {
0 | 1 => n,n => fib(n - 1) + fib(n - 2)
}}
![Page 21: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/21.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
fn gcd(mut n: u64, mut m: u64) -> u64 {assert!(n != 0 && m != 0);while m != 0 {
if m < n {let t = m; m=n; n=t;
}
m = m % n;}n
}
![Page 22: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/22.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Enums
enum Elements {Square,Circle
}
![Page 23: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/23.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Structs
struct Point3d {x: i32,y: i32,z: i32,
}let mut point = Point3d { x: 0, y: 0, z: 0 };
![Page 24: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/24.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Traits
struct Circle {x: f64,y: f64,radius: f64,
}trait HasArea {
fn area(&self) -> f64;}impl HasArea for Circle {
fn area(&self) -> f64 {std::f64::consts::PI *(self.radius * self.radius)
}}
![Page 25: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/25.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Generics
enum Option<T> {Some(T),None,
}
enum Result<T, E> {Ok(T),Err(E),
}
let foo: Option<f64> = Some(5.0f64);let foo: Option<u8> = None;let foo: Result<u8> = Ok(8);let foo: Result<i16> = Err(9);
![Page 26: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/26.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Generics
enum Option<T> {Some(T),None,
}
enum Result<T, E> {Ok(T),Err(E),
}
let foo: Option<f64> = Some(5.0f64);let foo: Option<u8> = None;let foo: Result<u8> = Ok(8);let foo: Result<i16> = Err(9);
![Page 27: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/27.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Generic Functions
fn min<T: Ord>(a: T, b: T) -> T {if a <= b { a } else { b }
}
Inline specialization
min(10i8, 20) == 10; //T is i8min(10, 20u32) == 10; //T is u32min("abc", "xyz") == "abc"; //strings are Ord
![Page 28: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/28.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Generic Functions
fn min<T: Ord>(a: T, b: T) -> T {if a <= b { a } else { b }
}
Inline specialization
min(10i8, 20) == 10; //T is i8min(10, 20u32) == 10; //T is u32min("abc", "xyz") == "abc"; //strings are Ord
![Page 29: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/29.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Composite types dependency
use std::fmt::Debug;fn foo<T: Clone + Debug>(x: T) {
x.clone();println!("{:?}", x);
}
![Page 30: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/30.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Refined implementation filter
impl<R: Num, C: Num> Add<Matrix<R, C>>for Matrix<R, C> {
...}
![Page 31: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/31.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Lazy evaluation
(1..).filter(|&x| x % 2 == 0).find(|x| *x > 42).take(5).collect::<Vec<i32>>();
![Page 32: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/32.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Imperative
let mut file = match File::open(file_path) {Ok(file) => file,Err(err) => return Err(err.to_string()),
};let mut contents = String::new();if let Err(err) =
file.read_to_string(&mut contents) {return Err(err.to_string());
}let n: i32 = match contents.trim().parse() {
Ok(n) => n,Err(err) => return Err(err.to_string()),
};Ok(2 * n)
![Page 33: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/33.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Functional
File::open(file_path).map_err(|err| err.to_string()).and_then(|mut file| {
let mut contents = String::new();file.read_to_string(&mut contents)
.map_err(|err| err.to_string())
.map(|_| contents)}).and_then(|contents| {contents.trim().parse::<i32>()
.map_err(|err| err.to_string())}).map(|n| 2 * n)
![Page 34: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/34.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Memory
![Page 35: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/35.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Rust way
▶ No null pointer deferences.▶ No dangling pointers▶ No buffer overruns
![Page 36: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/36.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Garbage collector
▶ Non deterministic▶ Runtime checking▶ Lack of control
Out of scope deallocation
![Page 37: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/37.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Garbage collector
▶ Non deterministic▶ Runtime checking▶ Lack of control
Out of scope deallocation
![Page 38: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/38.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Ownership
let v = vec![1, 2, 3];let v2 = v;println!("v[0] is: {}", v[0]);
error: use of moved value: `v`println!("v[0] is: {}", v[0]);
let v2 = &v;
![Page 39: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/39.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Ownership
let v = vec![1, 2, 3];let v2 = v;println!("v[0] is: {}", v[0]);
error: use of moved value: `v`println!("v[0] is: {}", v[0]);
let v2 = &v;
![Page 40: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/40.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Ownership
let v = vec![1, 2, 3];let v2 = v;println!("v[0] is: {}", v[0]);
error: use of moved value: `v`println!("v[0] is: {}", v[0]);
let v2 = &v;
![Page 41: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/41.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Borrowing
let v = vec![];foo(&v);fn foo(v: &Vec<i32>) {
println!("{}", v); //worksv.push(5); //fails
}
error: cannot borrow immutable borrowed content `*v` as mutablev.push(5);
![Page 42: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/42.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Borrowing
let v = vec![];foo(&v);fn foo(v: &Vec<i32>) {
println!("{}", v); //worksv.push(5); //fails
}
error: cannot borrow immutable borrowed content `*v` as mutablev.push(5);
![Page 43: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/43.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Borrowing Mutable
let mut x = 5;{
let y = &mut x;*y += 1;
}
println!("{}", x);
![Page 44: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/44.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Borrowing Rules
▶ a borrowed value can’t have greater lifetime▶ one or more immutable references (&T) to a resource,▶ exactly one mutable reference (&mut T).
![Page 45: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/45.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Lifetimes
fn firsts<'a 'b> (x: &'a Vec<i32> y: &'b Vec<i32>)-> (&'a i32, &'b i32) {
return (&x[0], &y[0]);}
![Page 46: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/46.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Concurrency
Shared mutable state (root of all evil)
4 feet tallOther languages tries to solve the mutable.Rust solves the shared
![Page 47: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/47.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Concurrency
Shared mutable state (root of all evil)4 feet tall
Other languages tries to solve the mutable.Rust solves the shared
![Page 48: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/48.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Concurrency
Shared mutable state (root of all evil)4 feet tallOther languages tries to solve the mutable.
Rust solves the shared
![Page 49: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/49.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Concurrency
Shared mutable state (root of all evil)4 feet tallOther languages tries to solve the mutable.Rust solves the shared
![Page 50: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/50.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Default thread
let thread1 = std::thread::spawn(|| {println!("foo");return 999;
});
let thread2 = std::thread::spawn(|| {println!("bar");return 666;
});
assert_eq!(try!(thread.join()), 999);assert_eq!(try!(thread.join()), 666);
![Page 51: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/51.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Shared thread
fn main() {let mut x = 1;let thread1 = std::thread::scoped(|| {x + 8});let thread2 = std::thread::scoped(|| {x + 27});assert_eq!(thread1.join() + thread2.join(), 37);
}
![Page 52: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/52.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Shared mutable thread
//arc = safe reference count//mutex = mutable data with lockinglet data = Arc::new(Mutex::new(vec![1,2,3]));
for i in 0..3 {let data = data.clone();thread::spawn(move || {
let mut data = data.lock().unwrap();data[0] += i;
});}
thread::sleep(Duration::from_millis(50));
![Page 53: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/53.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Tests
fn prime_factors(mut num: i64) -> Vec<i64> {let mut result = vec![];let mut i = 2;while num > 1 {
while num % i == 0 {result.push(i);num /= i;
}i +=1;
}
result}
![Page 54: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/54.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
#[test]fn prime_factors_of_48() {
assert_eq!(prime_factors(48), [2, 2, 2, 2, 3]);}
![Page 55: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/55.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Tests
#[test]#[should_panic(expected = "assertion failed")]fn it_works() {
assert_eq!("Hello", "world");}
![Page 56: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/56.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Tests as Documentation
//! ```//! assert_eq!(4, adder::add_two(2));//! ```
![Page 57: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/57.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Macros
let x: Vec<u32> = vec![1, 2, 3];
let x: Vec<u32> = {let mut temp_vec = Vec::new();temp_vec.push(1);temp_vec.push(2);temp_vec.push(3);temp_vec
};
![Page 58: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/58.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Macros
let x: Vec<u32> = vec![1, 2, 3];
let x: Vec<u32> = {let mut temp_vec = Vec::new();temp_vec.push(1);temp_vec.push(2);temp_vec.push(3);temp_vec
};
![Page 59: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/59.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Implementation
macro_rules! vec {( $( $x:expr ),* ) => {
{let mut temp_vec = Vec::new();$(
temp_vec.push($x);)*temp_vec
}};
}
![Page 60: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/60.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Cargo
Package managerrun/build/test/bench/update/init
![Page 61: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/61.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Libs
▶ rustup - croscompilling toolset▶ clap - parse command line args▶ iron - Web framework▶ helix - ruby classes in Rust▶ racer - auto-complete-er
![Page 62: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/62.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Beyond
▶ Module system▶ FFI Foreign functions interfaces▶ Unsafe▶ Much more!
![Page 63: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/63.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Cool Resources
▶ Blog: https://blog.rust-lang.org/▶ Rust by Example: http://rustbyexample.com/▶ Rust Book: https://doc.rust-lang.org▶ This week in Rust https://this-week-in-rust.org▶ Writing an OS in Rust: http://os.phil-opp.com/
![Page 64: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/64.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
References
▶ Platforms:https://hacks.Mozilla.org/2015/05/diving-into-rust-for-the-first-time/
▶ Comparison: https://www.rust-lang.org/faq.html#other-languages▶ Rust Programming Language:
http://www.slideshare.net/jaejukim9/rust-programming-language▶ State of Rust:
https://blog.rust-lang.org/2016/06/30/State-of-Rust-Survey-2016.html▶ Why Rust:▶ Which programs are fastest:
http://benchmarksgame.alioth.debian.org/u64q/which-programs-are-fastest.htmlhttp://www.oreilly.com/programming/free/files/why-rust.pdf
![Page 65: Introduction to Rust](https://reader031.vdocuments.mx/reader031/viewer/2022021506/589cf11c1a28abcc258b4f69/html5/thumbnails/65.jpg)
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
exit(0)