SlideShare ist ein Scribd-Unternehmen logo
1 von 74
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptDhruvin Shah
 
Rust Programming Language
Rust Programming LanguageRust Programming Language
Rust Programming LanguageJaeju Kim
 
Rust: Systems Programming for Everyone
Rust: Systems Programming for EveryoneRust: Systems Programming for Everyone
Rust: Systems Programming for EveryoneC4Media
 
Asynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFutureAsynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFutureJosé Paumard
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJSAbul Hasan
 
Introducing Async/Await
Introducing Async/AwaitIntroducing Async/Await
Introducing Async/AwaitValeri Karpov
 
Introduction to Linked Data 1/5
Introduction to Linked Data 1/5Introduction to Linked Data 1/5
Introduction to Linked Data 1/5Juan Sequeda
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions WebStackAcademy
 
OWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling PicklesOWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling PicklesChristopher Frohoff
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event LoopDesignveloper
 
The Rust Programming Language: an Overview
The Rust Programming Language: an OverviewThe Rust Programming Language: an Overview
The Rust Programming Language: an OverviewRoberto Casadei
 
WebAssembly Fundamentals
WebAssembly FundamentalsWebAssembly Fundamentals
WebAssembly FundamentalsKnoldus Inc.
 
Introduction to Apache ActiveMQ Artemis
Introduction to Apache ActiveMQ ArtemisIntroduction to Apache ActiveMQ Artemis
Introduction to Apache ActiveMQ ArtemisYoshimasa Tanabe
 

Was ist angesagt? (20)

Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Rust Programming Language
Rust Programming LanguageRust Programming Language
Rust Programming Language
 
Rust: Systems Programming for Everyone
Rust: Systems Programming for EveryoneRust: Systems Programming for Everyone
Rust: Systems Programming for Everyone
 
Asynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFutureAsynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFuture
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
 
Introducing Async/Await
Introducing Async/AwaitIntroducing Async/Await
Introducing Async/Await
 
Introduction to Linked Data 1/5
Introduction to Linked Data 1/5Introduction to Linked Data 1/5
Introduction to Linked Data 1/5
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 
Why rust?
Why rust?Why rust?
Why rust?
 
Introduction to Rust
Introduction to RustIntroduction to Rust
Introduction to Rust
 
OWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling PicklesOWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling Pickles
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 
Rust vs C++
Rust vs C++Rust vs C++
Rust vs C++
 
Rxjs ppt
Rxjs pptRxjs ppt
Rxjs ppt
 
The Rust Programming Language: an Overview
The Rust Programming Language: an OverviewThe Rust Programming Language: an Overview
The Rust Programming Language: an Overview
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
 
Rust-lang
Rust-langRust-lang
Rust-lang
 
WebAssembly Fundamentals
WebAssembly FundamentalsWebAssembly Fundamentals
WebAssembly Fundamentals
 
Introduction to Apache ActiveMQ Artemis
Introduction to Apache ActiveMQ ArtemisIntroduction to Apache ActiveMQ Artemis
Introduction to Apache ActiveMQ Artemis
 

Ähnlich wie Rust

Ownership System in Rust
Ownership System in RustOwnership System in Rust
Ownership System in RustChih-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.pptxGDSCVJTI
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchainedEduard Tomàs
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?勇浩 赖
 
Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011Scalac
 
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 #4Ismar Silveira
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan 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 developersPuneet Behl
 
Something about Golang
Something about GolangSomething about Golang
Something about GolangAnton 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
 

Ähnlich wie 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
 

Mehr von Chih-Hsuan Kuo

[Mozilla] content-select
[Mozilla] content-select[Mozilla] content-select
[Mozilla] content-selectChih-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 & 36Chih-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 GeckoChih-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 OSChih-Hsuan Kuo
 
Protocol handler in Gecko
Protocol handler in GeckoProtocol handler in Gecko
Protocol handler in GeckoChih-Hsuan Kuo
 
面試面試面試,因為很重要所以要說三次!
面試面試面試,因為很重要所以要說三次!面試面試面試,因為很重要所以要說三次!
面試面試面試,因為很重要所以要說三次!Chih-Hsuan Kuo
 
Windows 真的不好用...
Windows 真的不好用...Windows 真的不好用...
Windows 真的不好用...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
 

Mehr von 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
 

Kürzlich hochgeladen

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 

Kürzlich hochgeladen (20)

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 

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