SlideShare a Scribd company logo
RUST
郭⾄至軒 [:kuoe0]

kuoe0.tw@gmail.com

⾃自由的狐狸
NCKU
2008.09 ~ 2014.12
Programming Contests
Mozilla
2015.01 ~ 2018.01
Firefox Development
NEET
2018.01 ~ Present
Sleep until Noon
What Rust Is
System Programming
Language with Memory
Safety
Common Bugs
In C++
Memory Leak
/* C++ */
while (true) {
int* data = new int[10];
}
Dangling Pointer
Wild Pointer
/* C++ */
int* ptr1 = new int[10];
int* ptr2 = ptr1;
delete ptr2;
ptr1[0] = 0;
ptr2[1] = 1;
/* C++ */
int* ptr;
ptr[0] = 0;
Rust can Avoid Those Issues
in Compilation Time.
Memory Safety
In Rust
Rule 1
Each Value Has Only ONE Owner
Rule 2
Variable Releases OWNING VALUE when Destroying
Rule 3
Not Allow to Use INVALID Variables
let x = vec![1, 2, 3];
variable value
own
Rule 1
Each Value Has Only ONE Owner
Rule 2
Variable Releases OWNING VALUE when Destroying
Rule 3
Not Allow to Use INVALID Variables
not owning or borrowing any value
INVALID
Ownership Control
Lifetime Tracking
Copyable Type
Borrowing & Reference
Ownership Control
fn foo(v: Vec<i32>) {
println!("{:?}", v);
}
→ fn main() {
let a = vec![1; 5];
let b = a;
{
let c = b;
}
let d = vec![2; 5];
foo(d);
}
variables
values
fn foo(v: Vec<i32>) {
println!("{:?}", v);
}
fn main() {
→ let a = vec![1; 5];
let b = a;
{
let c = b;
}
let d = vec![2; 5];
foo(d);
}
a
vec![1;5]
variables
values
fn foo(v: Vec<i32>) {
println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
→ let b = a;
{
let c = b;
}
let d = vec![2; 5];
foo(d);
}
a b
vec![1;5]
variables
values
fn foo(v: Vec<i32>) {
println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
let b = a;
{
→ let c = b;
}
let d = vec![2; 5];
foo(d);
}
a b c
vec![1;5]
variables
values
fn foo(v: Vec<i32>) {
println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
let b = a;
{
let c = b;
}
→ let d = vec![2; 5];
foo(d);
}
a b c d
variables
values
vec![2;5]
fn foo(v: Vec<i32>) {
println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
let b = a;
{
let c = b;
}
let d = vec![2; 5];
→ foo(d);
}
a b c d
variables
values
vec![2;5]
→ fn foo(v: Vec<i32>) {
println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
let b = a;
{
let c = b;
}
let d = vec![2; 5];
foo(d);
}
a b c d v
variables
values
vec![2;5]
fn foo(v: Vec<i32>) {
→ println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
let b = a;
{
let c = b;
}
let d = vec![2; 5];
foo(d);
}
a b c d v
variables
values
vec![2;5]
fn foo(v: Vec<i32>) {
println!("{:?}", v);
→ }
fn main() {
let a = vec![1; 5];
let b = a;
{
let c = b;
}
let d = vec![2; 5];
foo(d);
}
a b c d
variables
values
fn foo(v: Vec<i32>) {
println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
let b = a;
{
let c = b;
}
let d = vec![2; 5];
foo(d);
→ }
variables
values
Lifetime Tracking
fn foo(v: Vec<i32>) {
println!("{:?}", v);
}
fn main() {
let a: Vec<i32>;
→ println!("{:?}", a);
let b = vec![1; 5];
let c = b;
→ println!("{:?}", b);
}
error[E0381]: use of possibly
uninitialized variable: `a`
--> src/main.rs:7:22
|
7 | println!("{:?}", a);
| ^ use of
| possibly uninitialized `a`
error[E0382]: use of moved value: `b`
--> src/main.rs:11:22
|
10 | let c = b;
| - value moved here
11 | println!("{:?}", b);
| ^ value used
|. here after move
|
Copyable Type
Type implemented Copy trait
do COPY instead of MOVE.
fn foo(v: i32) {
println!("{:?}", v);
}
→ fn main() {
let a = 10;
let b = a;
println!("{:?}", a);
let c = 20;
foo(c);
println!("{:?}", c);
}
variables
values
fn foo(v: i32) {
println!("{:?}", v);
}
fn main() {
→ let a = 10;
let b = a;
println!("{:?}", a);
let c = 20;
foo(c);
println!("{:?}", c);
}
variables
values
a
10
fn foo(v: i32) {
println!("{:?}", v);
}
fn main() {
let a = 10;
→ let b = a;
println!("{:?}", a);
let c = 20;
foo(c);
println!("{:?}", c);
}
variables
values
a b
10 10
fn foo(v: i32) {
println!("{:?}", v);
}
fn main() {
let a = 10;
let b = a;
→ println!("{:?}", a);
let c = 20;
foo(c);
println!("{:?}", c);
}
variables
values
a b
10 10
fn foo(v: i32) {
println!("{:?}", v);
}
fn main() {
let a = 10;
let b = a;
println!("{:?}", a);
→ let c = 20;
foo(c);
println!("{:?}", c);
}
variables
values
a b c
10 10 20
fn foo(v: i32) {
println!("{:?}", v);
}
fn main() {
let a = 10;
let b = a;
println!("{:?}", a);
let c = 20;
→ foo(c);
println!("{:?}", c);
}
variables
values
a b c
10 10 20
→ fn foo(v: i32) {
println!("{:?}", v);
}
fn main() {
let a = 10;
let b = a;
println!("{:?}", a);
let c = 20;
foo(c);
println!("{:?}", c);
}
variables
values
a b c v
10 10 20 20
fn foo(v: i32) {
→ println!("{:?}", v);
}
fn main() {
let a = 10;
let b = a;
println!("{:?}", a);
let c = 20;
foo(c);
println!("{:?}", c);
}
variables
values
a b c v
10 10 20 20
fn foo(v: i32) {
println!("{:?}", v);
→ }
fn main() {
let a = 10;
let b = a;
println!("{:?}", a);
let c = 20;
foo(c);
println!("{:?}", c);
}
variables
values
a b c
10 10 20
fn foo(v: i32) {
println!("{:?}", v);
}
fn main() {
let a = 10;
let b = a;
println!("{:?}", a);
let c = 20;
foo(c);
→ println!("{:?}", c);
}
variables
values
a b c
10 10 20
fn foo(v: i32) {
println!("{:?}", v);
}
fn main() {
let a = 10;
let b = a;
println!("{:?}", a);
let c = 20;
foo(c);
println!("{:?}", c);
→ }
variables
values
Borrowing & Reference
let x = vec![1, 2, 3];
let y = &x;
let x = vec![1, 2, 3];
let y = &x;
own
own
let x = vec![1, 2, 3];
let y = &x;
own
own
reference
let x = vec![1, 2, 3];
let y = &x;
own
own
reference
borrow
let x = vec![1, 2, 3];
let y = &x;
borrow
fn foo(v: &Vec<i32>) {
println!("{:?}", v);
}
→ fn main() {
let a = vec![1; 5];
let b = &a;
println!("{:?}", a);
let c = vec![2; 5];
foo(&c);
println!("{:?}", c);
}
variables
values
fn foo(v: &Vec<i32>) {
println!("{:?}", v);
}
fn main() {
→ let a = vec![1; 5];
let b = &a;
println!("{:?}", a);
let c = vec![2; 5];
foo(&c);
println!("{:?}", c);
}
variables
values
a
vec![1;5]
fn foo(v: &Vec<i32>) {
println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
→ let b = &a;
println!("{:?}", a);
let c = vec![2; 5];
foo(&c);
println!("{:?}", c);
}
variables
values
a b
vec![1;5]
fn foo(v: &Vec<i32>) {
println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
let b = &a;
→ println!("{:?}", a);
let c = vec![2; 5];
foo(&c);
println!("{:?}", c);
}
variables
values
a b
vec![1;5]
fn foo(v: &Vec<i32>) {
println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
let b = &a;
println!("{:?}", a);
→ let c = vec![2; 5];
foo(&c);
println!("{:?}", c);
}
variables
values
a b c
vec![2;5]vec![1;5]
fn foo(v: &Vec<i32>) {
println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
let b = &a;
println!("{:?}", a);
let c = vec![2; 5];
→ foo(&c);
println!("{:?}", c);
}
variables
values
a b c
vec![2;5]vec![1;5]
→ fn foo(v: &Vec<i32>) {
println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
let b = &a;
println!("{:?}", a);
let c = vec![2; 5];
foo(&c);
println!("{:?}", c);
}
variables
values
a b c v
vec![2;5]vec![1;5]
fn foo(v: &Vec<i32>) {
→ println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
let b = &a;
println!("{:?}", a);
let c = vec![2; 5];
foo(&c);
println!("{:?}", c);
}
variables
values
a b c v
vec![2;5]vec![1;5]
fn foo(v: &Vec<i32>) {
println!("{:?}", v);
→ }
fn main() {
let a = vec![1; 5];
let b = &a;
println!("{:?}", a);
let c = vec![2; 5];
foo(&c);
println!("{:?}", c);
}
variables
values
a b c
vec![2;5]vec![1;5]
fn foo(v: &Vec<i32>) {
println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
let b = &a;
println!("{:?}", a);
let c = vec![2; 5];
foo(&c);
→ println!("{:?}", c);
}
variables
values
a b c
vec![2;5]vec![1;5]
fn foo(v: &Vec<i32>) {
println!("{:?}", v);
}
fn main() {
let a = vec![1; 5];
let b = &a;
println!("{:?}", a);
let c = vec![2; 5];
foo(&c);
println!("{:?}", c);
→ }
variables
values
Cargo
Rust Package Manager
Build System
Dependencies Management
Test Framework
Documentation
Project Initialization
$ cargo new helloworld --bin
Create a new project with Cargo:
Generated files by `cargo new`:
$ tree helloworld
helloworld
!"" Cargo.toml
#"" src
#"" main.rs
Build & Run
$ cargo build
Compiling helloworld v0.1.0 (file:///helloworld)
Finished dev [unoptimized + debuginfo] target(s) in 4.60 secs
Build a project with cargo:
Run the executable program:
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
Running `target/debug/helloworld`
Hello, world!
Cargo.toml
[package]
# project name
name = "helloworld"
# project version
version = "0.1.0"
# auto info
authors = ["kuoe0 <kuoe0.tw@gmail.com>"]
[dependencies]
rand = "0.4.2" # random number generator
Cargo.toml
[package]
# project name
name = "helloworld"
# project version
version = "0.1.0"
# auto info
authors = ["kuoe0 <kuoe0.tw@gmail.com>"]
[dependencies]
rand = "0.4.2" # random number generator
Package Info
Dependencies List
Dependencies List
[package]
# project name
name = "helloworld"
# project version
version = "0.1.0"
# auto info
authors = ["kuoe0 <kuoe0.tw@gmail.com>"]
[dependencies]
rand = "0.4.2"
libc = "0.2.40"
bitflags = "1.0.3"
serde = "1.0.44"
log = "0.4.1"
$ cargo build
Updating registry `https://github.com/rust-lang/crates.io-
index`
Downloading libc v0.2.40
Downloading cfg-if v0.1.2
Downloading serde v1.0.44
Downloading bitflags v1.0.3
Downloading log v0.4.1
Downloading rand v0.4.2
Compiling libc v0.2.40
Compiling cfg-if v0.1.2
Compiling serde v1.0.44
Compiling bitflags v1.0.3
Compiling log v0.4.1
Compiling rand v0.4.2
Compiling helloworld v0.1.0 (file:///helloworld)
Finished dev [unoptimized + debuginfo] target(s) in 7.97 secs
Install dependencies with `cargo build`
Unit Test
extern crate rand;
fn gen_rand_int_less_100() -> u32 {
rand::random::<u32>() % 100
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn should_less_100() {
assert!(gen_rand_int_less_100() < 100);
}
}
$ cargo test
Compiling helloworld v0.1.0 (file:///private/tmp/helloworld)
Finished dev [unoptimized + debuginfo] target(s) in 0.48 secs
Running target/debug/deps/helloworld-7a8984a66f00dd7b
running 1 test
test tests::should_less_100 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0
filtered out
Run unit test with `cargo test`
Documentation
extern crate rand;
/// Return a random number in [0, 100)
///
/// # Example
///
/// ```
/// let r = gen_rand_int_less_100();
/// ```
pub fn gen_rand_int_less_100() -> u32 {
rand::random::<u32>() % 100
}
$ cargo doc
Documenting helloworld v0.1.0 (file:///private/tmp/helloworld)
Finished dev [unoptimized + debuginfo] target(s) in 1.14 secs
Generate the document with `cargo doc`
Firefox ♥ Rust
Use Rust in Firefox
Servo Browser Engine
A browser engine written in Rust with parallel mechanism
Servo Browser Engine
A browser engine written in Rust with parallel mechanism
Quantum CSS (a.k.a. Stylo)
Use the parallel style engine from Servo in Firefox
Firefox Style Engine Servo Style Engine
replace
Q & A

More Related Content

What's hot

Rust-lang
Rust-langRust-lang
Deep drive into rust programming language
Deep drive into rust programming languageDeep drive into rust programming language
Deep drive into rust programming language
Vigneshwer Dhinakaran
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
Rob Eisenberg
 
Introduction to Rust language programming
Introduction to Rust language programmingIntroduction to Rust language programming
Introduction to Rust language programming
Rodolfo Finochietti
 
The Rust Programming Language: an Overview
The Rust Programming Language: an OverviewThe Rust Programming Language: an Overview
The Rust Programming Language: an Overview
Roberto Casadei
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
Izzet Mustafaiev
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
boyney123
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
Derek Willian Stavis
 
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
Edureka!
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
L&T Technology Services Limited
 
An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...
Claudio Capobianco
 
gRPC in Go
gRPC in GogRPC in Go
gRPC in Go
Almog Baku
 
The Rust Programming Language
The Rust Programming LanguageThe Rust Programming Language
The Rust Programming Language
Mario Alexandro Santini
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
Eyal Vardi
 
Kotlin Coroutines in Practice @ KotlinConf 2018
Kotlin Coroutines in Practice @ KotlinConf 2018Kotlin Coroutines in Practice @ KotlinConf 2018
Kotlin Coroutines in Practice @ KotlinConf 2018
Roman Elizarov
 
Rust: Systems Programming for Everyone
Rust: Systems Programming for EveryoneRust: Systems Programming for Everyone
Rust: Systems Programming for Everyone
C4Media
 
Svelte the future of frontend development
Svelte   the future of frontend developmentSvelte   the future of frontend development
Svelte the future of frontend development
twilson63
 
Angular and The Case for RxJS
Angular and The Case for RxJSAngular and The Case for RxJS
Angular and The Case for RxJS
Sandi Barr
 
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
 Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t... Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
AboutYouGmbH
 
Rust system programming language
Rust system programming languageRust system programming language
Rust system programming language
robin_sy
 

What's hot (20)

Rust-lang
Rust-langRust-lang
Rust-lang
 
Deep drive into rust programming language
Deep drive into rust programming languageDeep drive into rust programming language
Deep drive into rust programming language
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 
Introduction to Rust language programming
Introduction to Rust language programmingIntroduction to Rust language programming
Introduction to Rust language programming
 
The Rust Programming Language: an Overview
The Rust Programming Language: an OverviewThe Rust Programming Language: an Overview
The Rust Programming Language: an Overview
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Train...
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...
 
gRPC in Go
gRPC in GogRPC in Go
gRPC in Go
 
The Rust Programming Language
The Rust Programming LanguageThe Rust Programming Language
The Rust Programming Language
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Kotlin Coroutines in Practice @ KotlinConf 2018
Kotlin Coroutines in Practice @ KotlinConf 2018Kotlin Coroutines in Practice @ KotlinConf 2018
Kotlin Coroutines in Practice @ KotlinConf 2018
 
Rust: Systems Programming for Everyone
Rust: Systems Programming for EveryoneRust: Systems Programming for Everyone
Rust: Systems Programming for Everyone
 
Svelte the future of frontend development
Svelte   the future of frontend developmentSvelte   the future of frontend development
Svelte the future of frontend development
 
Angular and The Case for RxJS
Angular and The Case for RxJSAngular and The Case for RxJS
Angular and The Case for RxJS
 
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
 Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t... Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
 
Rust system programming language
Rust system programming languageRust system programming language
Rust system programming language
 

Similar to Rust

Rustlabs Quick Start
Rustlabs Quick StartRustlabs Quick Start
Rustlabs Quick Start
sangam biradar
 
Ownership System in Rust
Ownership System in RustOwnership System in Rust
Ownership System in Rust
Chih-Hsuan Kuo
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017
pramode_ce
 
GDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptxGDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptx
GDSCVJTI
 
ES2015 New Features
ES2015 New FeaturesES2015 New Features
ES2015 New Features
Giacomo Zinetti
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
Eduard Tomàs
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
André Faria Gomes
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
勇浩 赖
 
Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011
Scalac
 
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Codemotion
 
Effective C#
Effective C#Effective C#
Effective C#
lantoli
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
Ismar Silveira
 
Go is geting Rusty
Go is geting RustyGo is geting Rusty
Go is geting Rusty
👋 Alon Nativ
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
"О некоторых особенностях Objective-C++" Влад Михайленко (Maps.Me)
"О некоторых особенностях Objective-C++" Влад Михайленко (Maps.Me)"О некоторых особенностях Objective-C++" Влад Михайленко (Maps.Me)
"О некоторых особенностях Objective-C++" Влад Михайленко (Maps.Me)
AvitoTech
 
Groovy for java developers
Groovy for java developersGroovy for java developers
Groovy for java developers
Puneet Behl
 
Something about Golang
Something about GolangSomething about Golang
Something about Golang
Anton Arhipov
 
Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)
Davide Cerbo
 

Similar to Rust (20)

Rustlabs Quick Start
Rustlabs Quick StartRustlabs Quick Start
Rustlabs Quick Start
 
Ownership System in Rust
Ownership System in RustOwnership System in Rust
Ownership System in Rust
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017
 
GDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptxGDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptx
 
ES2015 New Features
ES2015 New FeaturesES2015 New Features
ES2015 New Features
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
 
Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011
 
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
 
Effective C#
Effective C#Effective C#
Effective C#
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Go is geting Rusty
Go is geting RustyGo is geting Rusty
Go is geting Rusty
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
"О некоторых особенностях Objective-C++" Влад Михайленко (Maps.Me)
"О некоторых особенностях Objective-C++" Влад Михайленко (Maps.Me)"О некоторых особенностях Objective-C++" Влад Михайленко (Maps.Me)
"О некоторых особенностях Objective-C++" Влад Михайленко (Maps.Me)
 
Groovy for java developers
Groovy for java developersGroovy for java developers
Groovy for java developers
 
Something about Golang
Something about GolangSomething about Golang
Something about Golang
 
Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)
 
C program
C programC program
C program
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 

More from Chih-Hsuan Kuo

[Mozilla] content-select
[Mozilla] content-select[Mozilla] content-select
[Mozilla] content-select
Chih-Hsuan Kuo
 
在開始工作以前,我以為我會寫扣。
在開始工作以前,我以為我會寫扣。在開始工作以前,我以為我會寫扣。
在開始工作以前,我以為我會寫扣。
Chih-Hsuan Kuo
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36
Chih-Hsuan Kuo
 
Use C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoUse C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in Gecko
Chih-Hsuan Kuo
 
Pocket Authentication with OAuth on Firefox OS
Pocket Authentication with OAuth on Firefox OSPocket Authentication with OAuth on Firefox OS
Pocket Authentication with OAuth on Firefox OS
Chih-Hsuan Kuo
 
Necko walkthrough
Necko walkthroughNecko walkthrough
Necko walkthrough
Chih-Hsuan Kuo
 
Protocol handler in Gecko
Protocol handler in GeckoProtocol handler in Gecko
Protocol handler in Gecko
Chih-Hsuan Kuo
 
面試面試面試,因為很重要所以要說三次!
面試面試面試,因為很重要所以要說三次!面試面試面試,因為很重要所以要說三次!
面試面試面試,因為很重要所以要說三次!
Chih-Hsuan Kuo
 
面試心得分享
面試心得分享面試心得分享
面試心得分享
Chih-Hsuan Kuo
 
Windows 真的不好用...
Windows 真的不好用...Windows 真的不好用...
Windows 真的不好用...
Chih-Hsuan Kuo
 
Python @Wheel Lab
Python @Wheel LabPython @Wheel Lab
Python @Wheel Lab
Chih-Hsuan Kuo
 
Introduction to VP8
Introduction to VP8Introduction to VP8
Introduction to VP8
Chih-Hsuan Kuo
 
Python @NCKU CSIE
Python @NCKU CSIEPython @NCKU CSIE
Python @NCKU CSIE
Chih-Hsuan Kuo
 
[ACM-ICPC] Tree Isomorphism
[ACM-ICPC] Tree Isomorphism[ACM-ICPC] Tree Isomorphism
[ACM-ICPC] Tree IsomorphismChih-Hsuan Kuo
 
[ACM-ICPC] Dinic's Algorithm
[ACM-ICPC] Dinic's Algorithm[ACM-ICPC] Dinic's Algorithm
[ACM-ICPC] Dinic's AlgorithmChih-Hsuan Kuo
 
[ACM-ICPC] Disjoint Set
[ACM-ICPC] Disjoint Set[ACM-ICPC] Disjoint Set
[ACM-ICPC] Disjoint SetChih-Hsuan Kuo
 

More from Chih-Hsuan Kuo (20)

[Mozilla] content-select
[Mozilla] content-select[Mozilla] content-select
[Mozilla] content-select
 
在開始工作以前,我以為我會寫扣。
在開始工作以前,我以為我會寫扣。在開始工作以前,我以為我會寫扣。
在開始工作以前,我以為我會寫扣。
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36
 
Use C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoUse C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in Gecko
 
Pocket Authentication with OAuth on Firefox OS
Pocket Authentication with OAuth on Firefox OSPocket Authentication with OAuth on Firefox OS
Pocket Authentication with OAuth on Firefox OS
 
Necko walkthrough
Necko walkthroughNecko walkthrough
Necko walkthrough
 
Protocol handler in Gecko
Protocol handler in GeckoProtocol handler in Gecko
Protocol handler in Gecko
 
面試面試面試,因為很重要所以要說三次!
面試面試面試,因為很重要所以要說三次!面試面試面試,因為很重要所以要說三次!
面試面試面試,因為很重要所以要說三次!
 
應徵軟體工程師
應徵軟體工程師應徵軟體工程師
應徵軟體工程師
 
面試心得分享
面試心得分享面試心得分享
面試心得分享
 
Windows 真的不好用...
Windows 真的不好用...Windows 真的不好用...
Windows 真的不好用...
 
Python @Wheel Lab
Python @Wheel LabPython @Wheel Lab
Python @Wheel Lab
 
Introduction to VP8
Introduction to VP8Introduction to VP8
Introduction to VP8
 
Python @NCKU CSIE
Python @NCKU CSIEPython @NCKU CSIE
Python @NCKU CSIE
 
[ACM-ICPC] Tree Isomorphism
[ACM-ICPC] Tree Isomorphism[ACM-ICPC] Tree Isomorphism
[ACM-ICPC] Tree Isomorphism
 
[ACM-ICPC] Dinic's Algorithm
[ACM-ICPC] Dinic's Algorithm[ACM-ICPC] Dinic's Algorithm
[ACM-ICPC] Dinic's Algorithm
 
[ACM-ICPC] Disjoint Set
[ACM-ICPC] Disjoint Set[ACM-ICPC] Disjoint Set
[ACM-ICPC] Disjoint Set
 
[ACM-ICPC] Traversal
[ACM-ICPC] Traversal[ACM-ICPC] Traversal
[ACM-ICPC] Traversal
 
[ACM-ICPC] UVa-10245
[ACM-ICPC] UVa-10245[ACM-ICPC] UVa-10245
[ACM-ICPC] UVa-10245
 
[ACM-ICPC] Sort
[ACM-ICPC] Sort[ACM-ICPC] Sort
[ACM-ICPC] Sort
 

Recently uploaded

First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 

Recently uploaded (20)

First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 

Rust

  • 2. NCKU 2008.09 ~ 2014.12 Programming Contests Mozilla 2015.01 ~ 2018.01 Firefox Development NEET 2018.01 ~ Present Sleep until Noon
  • 6. Memory Leak /* C++ */ while (true) { int* data = new int[10]; } Dangling Pointer Wild Pointer /* C++ */ int* ptr1 = new int[10]; int* ptr2 = ptr1; delete ptr2; ptr1[0] = 0; ptr2[1] = 1; /* C++ */ int* ptr; ptr[0] = 0;
  • 7. Rust can Avoid Those Issues in Compilation Time.
  • 9. Rule 1 Each Value Has Only ONE Owner Rule 2 Variable Releases OWNING VALUE when Destroying Rule 3 Not Allow to Use INVALID Variables
  • 10. let x = vec![1, 2, 3]; variable value own
  • 11. Rule 1 Each Value Has Only ONE Owner Rule 2 Variable Releases OWNING VALUE when Destroying Rule 3 Not Allow to Use INVALID Variables not owning or borrowing any value INVALID
  • 12. Ownership Control Lifetime Tracking Copyable Type Borrowing & Reference
  • 14. fn foo(v: Vec<i32>) { println!("{:?}", v); } → fn main() { let a = vec![1; 5]; let b = a; { let c = b; } let d = vec![2; 5]; foo(d); } variables values
  • 15. fn foo(v: Vec<i32>) { println!("{:?}", v); } fn main() { → let a = vec![1; 5]; let b = a; { let c = b; } let d = vec![2; 5]; foo(d); } a vec![1;5] variables values
  • 16. fn foo(v: Vec<i32>) { println!("{:?}", v); } fn main() { let a = vec![1; 5]; → let b = a; { let c = b; } let d = vec![2; 5]; foo(d); } a b vec![1;5] variables values
  • 17. fn foo(v: Vec<i32>) { println!("{:?}", v); } fn main() { let a = vec![1; 5]; let b = a; { → let c = b; } let d = vec![2; 5]; foo(d); } a b c vec![1;5] variables values
  • 18. fn foo(v: Vec<i32>) { println!("{:?}", v); } fn main() { let a = vec![1; 5]; let b = a; { let c = b; } → let d = vec![2; 5]; foo(d); } a b c d variables values vec![2;5]
  • 19. fn foo(v: Vec<i32>) { println!("{:?}", v); } fn main() { let a = vec![1; 5]; let b = a; { let c = b; } let d = vec![2; 5]; → foo(d); } a b c d variables values vec![2;5]
  • 20. → fn foo(v: Vec<i32>) { println!("{:?}", v); } fn main() { let a = vec![1; 5]; let b = a; { let c = b; } let d = vec![2; 5]; foo(d); } a b c d v variables values vec![2;5]
  • 21. fn foo(v: Vec<i32>) { → println!("{:?}", v); } fn main() { let a = vec![1; 5]; let b = a; { let c = b; } let d = vec![2; 5]; foo(d); } a b c d v variables values vec![2;5]
  • 22. fn foo(v: Vec<i32>) { println!("{:?}", v); → } fn main() { let a = vec![1; 5]; let b = a; { let c = b; } let d = vec![2; 5]; foo(d); } a b c d variables values
  • 23. fn foo(v: Vec<i32>) { println!("{:?}", v); } fn main() { let a = vec![1; 5]; let b = a; { let c = b; } let d = vec![2; 5]; foo(d); → } variables values
  • 25. fn foo(v: Vec<i32>) { println!("{:?}", v); } fn main() { let a: Vec<i32>; → println!("{:?}", a); let b = vec![1; 5]; let c = b; → println!("{:?}", b); } error[E0381]: use of possibly uninitialized variable: `a` --> src/main.rs:7:22 | 7 | println!("{:?}", a); | ^ use of | possibly uninitialized `a` error[E0382]: use of moved value: `b` --> src/main.rs:11:22 | 10 | let c = b; | - value moved here 11 | println!("{:?}", b); | ^ value used |. here after move |
  • 27. Type implemented Copy trait do COPY instead of MOVE.
  • 28. fn foo(v: i32) { println!("{:?}", v); } → fn main() { let a = 10; let b = a; println!("{:?}", a); let c = 20; foo(c); println!("{:?}", c); } variables values
  • 29. fn foo(v: i32) { println!("{:?}", v); } fn main() { → let a = 10; let b = a; println!("{:?}", a); let c = 20; foo(c); println!("{:?}", c); } variables values a 10
  • 30. fn foo(v: i32) { println!("{:?}", v); } fn main() { let a = 10; → let b = a; println!("{:?}", a); let c = 20; foo(c); println!("{:?}", c); } variables values a b 10 10
  • 31. fn foo(v: i32) { println!("{:?}", v); } fn main() { let a = 10; let b = a; → println!("{:?}", a); let c = 20; foo(c); println!("{:?}", c); } variables values a b 10 10
  • 32. fn foo(v: i32) { println!("{:?}", v); } fn main() { let a = 10; let b = a; println!("{:?}", a); → let c = 20; foo(c); println!("{:?}", c); } variables values a b c 10 10 20
  • 33. fn foo(v: i32) { println!("{:?}", v); } fn main() { let a = 10; let b = a; println!("{:?}", a); let c = 20; → foo(c); println!("{:?}", c); } variables values a b c 10 10 20
  • 34. → fn foo(v: i32) { println!("{:?}", v); } fn main() { let a = 10; let b = a; println!("{:?}", a); let c = 20; foo(c); println!("{:?}", c); } variables values a b c v 10 10 20 20
  • 35. fn foo(v: i32) { → println!("{:?}", v); } fn main() { let a = 10; let b = a; println!("{:?}", a); let c = 20; foo(c); println!("{:?}", c); } variables values a b c v 10 10 20 20
  • 36. fn foo(v: i32) { println!("{:?}", v); → } fn main() { let a = 10; let b = a; println!("{:?}", a); let c = 20; foo(c); println!("{:?}", c); } variables values a b c 10 10 20
  • 37. fn foo(v: i32) { println!("{:?}", v); } fn main() { let a = 10; let b = a; println!("{:?}", a); let c = 20; foo(c); → println!("{:?}", c); } variables values a b c 10 10 20
  • 38. fn foo(v: i32) { println!("{:?}", v); } fn main() { let a = 10; let b = a; println!("{:?}", a); let c = 20; foo(c); println!("{:?}", c); → } variables values
  • 40. let x = vec![1, 2, 3]; let y = &x;
  • 41. let x = vec![1, 2, 3]; let y = &x; own own
  • 42. let x = vec![1, 2, 3]; let y = &x; own own reference
  • 43. let x = vec![1, 2, 3]; let y = &x; own own reference borrow
  • 44. let x = vec![1, 2, 3]; let y = &x; borrow
  • 45. fn foo(v: &Vec<i32>) { println!("{:?}", v); } → fn main() { let a = vec![1; 5]; let b = &a; println!("{:?}", a); let c = vec![2; 5]; foo(&c); println!("{:?}", c); } variables values
  • 46. fn foo(v: &Vec<i32>) { println!("{:?}", v); } fn main() { → let a = vec![1; 5]; let b = &a; println!("{:?}", a); let c = vec![2; 5]; foo(&c); println!("{:?}", c); } variables values a vec![1;5]
  • 47. fn foo(v: &Vec<i32>) { println!("{:?}", v); } fn main() { let a = vec![1; 5]; → let b = &a; println!("{:?}", a); let c = vec![2; 5]; foo(&c); println!("{:?}", c); } variables values a b vec![1;5]
  • 48. fn foo(v: &Vec<i32>) { println!("{:?}", v); } fn main() { let a = vec![1; 5]; let b = &a; → println!("{:?}", a); let c = vec![2; 5]; foo(&c); println!("{:?}", c); } variables values a b vec![1;5]
  • 49. fn foo(v: &Vec<i32>) { println!("{:?}", v); } fn main() { let a = vec![1; 5]; let b = &a; println!("{:?}", a); → let c = vec![2; 5]; foo(&c); println!("{:?}", c); } variables values a b c vec![2;5]vec![1;5]
  • 50. fn foo(v: &Vec<i32>) { println!("{:?}", v); } fn main() { let a = vec![1; 5]; let b = &a; println!("{:?}", a); let c = vec![2; 5]; → foo(&c); println!("{:?}", c); } variables values a b c vec![2;5]vec![1;5]
  • 51. → fn foo(v: &Vec<i32>) { println!("{:?}", v); } fn main() { let a = vec![1; 5]; let b = &a; println!("{:?}", a); let c = vec![2; 5]; foo(&c); println!("{:?}", c); } variables values a b c v vec![2;5]vec![1;5]
  • 52. fn foo(v: &Vec<i32>) { → println!("{:?}", v); } fn main() { let a = vec![1; 5]; let b = &a; println!("{:?}", a); let c = vec![2; 5]; foo(&c); println!("{:?}", c); } variables values a b c v vec![2;5]vec![1;5]
  • 53. fn foo(v: &Vec<i32>) { println!("{:?}", v); → } fn main() { let a = vec![1; 5]; let b = &a; println!("{:?}", a); let c = vec![2; 5]; foo(&c); println!("{:?}", c); } variables values a b c vec![2;5]vec![1;5]
  • 54. fn foo(v: &Vec<i32>) { println!("{:?}", v); } fn main() { let a = vec![1; 5]; let b = &a; println!("{:?}", a); let c = vec![2; 5]; foo(&c); → println!("{:?}", c); } variables values a b c vec![2;5]vec![1;5]
  • 55. fn foo(v: &Vec<i32>) { println!("{:?}", v); } fn main() { let a = vec![1; 5]; let b = &a; println!("{:?}", a); let c = vec![2; 5]; foo(&c); println!("{:?}", c); → } variables values
  • 57. Build System Dependencies Management Test Framework Documentation
  • 58. Project Initialization $ cargo new helloworld --bin Create a new project with Cargo: Generated files by `cargo new`: $ tree helloworld helloworld !"" Cargo.toml #"" src #"" main.rs
  • 59. Build & Run $ cargo build Compiling helloworld v0.1.0 (file:///helloworld) Finished dev [unoptimized + debuginfo] target(s) in 4.60 secs Build a project with cargo: Run the executable program: $ cargo run Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs Running `target/debug/helloworld` Hello, world!
  • 60. Cargo.toml [package] # project name name = "helloworld" # project version version = "0.1.0" # auto info authors = ["kuoe0 <kuoe0.tw@gmail.com>"] [dependencies] rand = "0.4.2" # random number generator
  • 61. Cargo.toml [package] # project name name = "helloworld" # project version version = "0.1.0" # auto info authors = ["kuoe0 <kuoe0.tw@gmail.com>"] [dependencies] rand = "0.4.2" # random number generator Package Info Dependencies List
  • 62. Dependencies List [package] # project name name = "helloworld" # project version version = "0.1.0" # auto info authors = ["kuoe0 <kuoe0.tw@gmail.com>"] [dependencies] rand = "0.4.2" libc = "0.2.40" bitflags = "1.0.3" serde = "1.0.44" log = "0.4.1"
  • 63. $ cargo build Updating registry `https://github.com/rust-lang/crates.io- index` Downloading libc v0.2.40 Downloading cfg-if v0.1.2 Downloading serde v1.0.44 Downloading bitflags v1.0.3 Downloading log v0.4.1 Downloading rand v0.4.2 Compiling libc v0.2.40 Compiling cfg-if v0.1.2 Compiling serde v1.0.44 Compiling bitflags v1.0.3 Compiling log v0.4.1 Compiling rand v0.4.2 Compiling helloworld v0.1.0 (file:///helloworld) Finished dev [unoptimized + debuginfo] target(s) in 7.97 secs Install dependencies with `cargo build`
  • 64. Unit Test extern crate rand; fn gen_rand_int_less_100() -> u32 { rand::random::<u32>() % 100 } #[cfg(test)] mod tests { use super::*; #[test] fn should_less_100() { assert!(gen_rand_int_less_100() < 100); } }
  • 65. $ cargo test Compiling helloworld v0.1.0 (file:///private/tmp/helloworld) Finished dev [unoptimized + debuginfo] target(s) in 0.48 secs Running target/debug/deps/helloworld-7a8984a66f00dd7b running 1 test test tests::should_less_100 ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out Run unit test with `cargo test`
  • 66. Documentation extern crate rand; /// Return a random number in [0, 100) /// /// # Example /// /// ``` /// let r = gen_rand_int_less_100(); /// ``` pub fn gen_rand_int_less_100() -> u32 { rand::random::<u32>() % 100 }
  • 67. $ cargo doc Documenting helloworld v0.1.0 (file:///private/tmp/helloworld) Finished dev [unoptimized + debuginfo] target(s) in 1.14 secs Generate the document with `cargo doc`
  • 68.
  • 69. Firefox ♥ Rust Use Rust in Firefox
  • 70. Servo Browser Engine A browser engine written in Rust with parallel mechanism
  • 71. Servo Browser Engine A browser engine written in Rust with parallel mechanism Quantum CSS (a.k.a. Stylo) Use the parallel style engine from Servo in Firefox
  • 72. Firefox Style Engine Servo Style Engine replace
  • 73.
  • 74. Q & A