SlideShare a Scribd company logo
Rustとは
パヴェウ・ルシン
株式会社ブリリアントサービス
2015.04.07
 自己紹介
 会社の紹介
 なぜRustか?
 Rustの基本
アジェンダ
 Paweł Rusin (パヴェウ・ルシン)
 pawel.rusin@brilliantservice.co.jp
Facebook: Paweł Rusin (iofar@o2.pl)
Twitter: RusinPaw
 会社:
 株式会社ブリリアントサービス
 業務:
開発部のエンジニア(主にiOSアプリケーショ
ン開発)
自己紹介
 株式会社ブリリアントサービス
 本社:大阪
 支社:東京(品川)、シリコンバレー
 アプリケーション開発、O2Oサービス開発、スマートデ
バイス開発
会社の紹介
 ジェスチャーで操作できる電脳メガネ
 ジェスチャー認識システム
 拡張現実で独特な体験を提供
 FreeBSDベース
 開発言語はCとObjective-C...
miramaについて
Objective-C
Swift
C Objective-C
システム
パーフォーマンス
OO
P
豊かなstandard library
?
モダーン
安定(メモリー管理)
書きやすい
他の希望特徴
Rustとは
●
2009年からMozilla Researchで開発しているプログラ
ミング言語
●
マルチパラタイム(純関数型、オブジェクト指向な
ど)
●
クライアントーサーバーアピリケーションに向け
●
特徴:メモリー・セーフ、並列性
●
開発中:現在点1.0.0 beta(2015年5月ver1.0リリス予
定)
Rust言語紹介
参照
●
Rust book: https://doc.rust-lang.org/book/ (nightly bu
ild)
●
Rust documentation: http://doc.rust-lang.org/
●
IRC irc.mozilla.org #rust
$ curl -sf -L https://static.rust-lang.org/rustup.sh | sudo sh
$ curl -f -L https://static.rust-lang.org/rustup.sh -O
$ sudo sh rustup.sh
インストール仕
方
バイナリかソースからインストール可能:
http://www.rust-lang.org/install.html
$ git clone https://github.com/yohanesu/tokyorust-part1
fn main() {
println!("Hello World!");
}
example1.rs
マクロ
$ rustc example1.rc
$ ./example1
fn main() {
let n = 5;
if n < 0 {
println!("{} is negative", n);
} else if n > 0 {
println!("{} is positive", n);
} else {
println!("{} is zero", n);
}
}
example2.rs
Non-mutable!
struct Rectangle{
x : i32,
y : i32
}
impl Rectangle{
fn area(&self) -> i32{
self.x*self.y
}
}
fn main() {
let rect = Rectangle{x:2,y:3};
println!("Rectangle area is {}",rect.area());
}
example3.rs (OO
P) struct定義でIV
struct実装でメソッド
example4.rs (純関数
型)
不安定機能#![feature(core)]
#![feature(collections)]
use std::iter::AdditiveIterator;
fn main() {
let kanji_array : [String;3] = [
String::from_str("Rust is fun."),
String::from_str("You can use High Order Functions."),
String::from_str("I want to learn more.")];
let char_count = kanji_array.iter().map(|s : &String|s.len()).sum();
println!("Character count: {}", char_count);
}
example4.rs (純関数型)
Rust is fun!
You can use High Order Functions!
I want to learn more!
12
33
21
61
sum()
String.len()
String.len()
String.len()
map()
メモリー管理
●
バッグの原因:
– freeしない(メモリーリーク)
– freeされたメモリーを使用
– 二回目free
– Null pointer dereference
●
対策
– Smart pointers
– Garbage collector
– ARC (Automatic reference counting)
borrow.rs (メモリー管理)
fn main() {
let x = 4;
let y = &x;
println!("Address of x is {:p} address of y is
{:p}",&x,y);
}
Address of x is 0x7fff5fa1795c address of y is 0x7fff5fa1795c
–メモリー管理 immutable borr
ow
x x x
y
z
example5.rs (メモリー管
理)
fn main() {
let x = 4;
let y = &x;
println!("Address of x is {:p} address of y is
{:p}",&x,y);
*y = 1;
}
borrow.rs:6:4: 6:10 error: cannot assign to immutable borrowed content
`*y`
borrow.rs:6 *y = 1;
^~~~~~
error: aborting due to previous error
example5.rs (メモリー管
理)
fn main() {
let mut x = 4;
let y = &x;
println!("Address of x is {:p} address of y is
{:p}",&x,y);
*y = 1;
}
borrow.rs:6:4: 6:10 error: cannot assign to immutable borrowed content
`*y`
borrow.rs:6 *y = 1;
^~~~~~
error: aborting due to previous error
example5.rs (メモリー管
理)
fn main() {
let mut x = 4;
let y = &mut x;
println!("Address of x is {:p} address of y is
{:p}",&x,y);
*y = 1;
}
borrow.rs:5:58: 5:59 error: cannot borrow `x` as immutable because it is
also borrowed as mutable
borrow.rs:5 println!("Address of x is {:p} address of y is {:p}",&x,y);
^
note: in expansion of format_args!
<std macros>:2:25: 2:58 note: expansion site
<std macros>:1:1: 2:62 note: in expansion of print!
<std macros>:3:1: 3:54 note: expansion site
<std macros>:1:1: 3:58 note: in expansion of println!
borrow.rs:5:4: 5:63 note: expansion site
borrow.rs:4:17: 4:18 note: previous borrow of `x` occurs here; the mutable
borrow prevents subsequent moves, borrows, or modification of `x` until
the borrow ends
borrow.rs:4 let y = &mut x;
^
borrow.rs:7:2: 7:2 note: previous borrow ends here
borrow.rs:1 fn main() {
...
borrow.rs:7 }
^
error: aborting due to previous error
example5.rs (メモリー管
理)
fn main() {
let mut x = 4;
let y = &mut x;
println!("Address of x is {:p} address of y is
{:p}",&x,y);
*y = 1;
}
borrow.rs:5:58: 5:59 error: cannot borrow `x` as immutable because it is
also borrowed as mutable
borrow.rs:5 println!("Address of x is {:p} address of y is {:p}",&x,y);
^
note: in expansion of format_args!
<std macros>:2:25: 2:58 note: expansion site
<std macros>:1:1: 2:62 note: in expansion of print!
<std macros>:3:1: 3:54 note: expansion site
<std macros>:1:1: 3:58 note: in expansion of println!
borrow.rs:5:4: 5:63 note: expansion site
borrow.rs:4:17: 4:18 note: previous borrow of `x` occurs here; the mutable
borrow prevents subsequent moves, borrows, or modification of `x` until
the borrow ends
borrow.rs:4 let y = &mut x;
^
borrow.rs:7:2: 7:2 note: previous borrow ends here
borrow.rs:1 fn main() {
...
borrow.rs:7 }
^
error: aborting due to previous error
example5.rs (メモリー管
理)
fn main() {
let mut x = 4;
let y = &mut x;
//println!("Address of x is {:p} address of y is {:p}",&x,y);
*y = 1;
}
成功!
example5.rs (メモリー管
理)
fn main() {
let mut x = 4;
if true {
let y = &mut x;
println!("Address of y is {:p}",y);
*y = 1;
}
println!("Address of x is {:p}",&x);
}
Address of y is 0x7fff51b4795c
Address of x is 0x7fff51b4795c
yのlifetime = 借りる範囲
–メモリー管理 mutable borrow
mut x x mut x
mut y
example5.rs (メモリー管
理)
fn main() {
let x = Box::new(4);
let y = x;
println!("Value of y is {}",y);
}
Value of y is 4
example5.rs (メモリー管
理)
fn main() {
let x = Box::new(4);
let y = x;
println!("Value of y is {}",y);
println!("Value of x is {}",x);
}
borrow.rs:6:32: 6:33 error: use of moved value: `x`
borrow.rs:6 println!("Value of x is {}",x);
^
note: in expansion of format_args!
<std macros>:2:25: 2:58 note: expansion site
<std macros>:1:1: 2:62 note: in expansion of print!
<std macros>:3:1: 3:54 note: expansion site
<std macros>:1:1: 3:58 note: in expansion of println!
borrow.rs:6:4: 6:35 note: expansion site
borrow.rs:4:8: 4:9 note: `x` moved here because it has type
`Box<i32>`, which is moved by default
borrow.rs:4 let y = x;
^
borrow.rs:4:9: 4:9 help: use `ref` to override
error: aborting due to previous error
example5.rs (メモリー管
理)fn main() {
let x = Box::new(4);
println!("Value of x is {}",x);
if true {
let y = x;
println!("Value of y is {}",y);
}
println!("Value of x is {}",x);
}
borrow.rs:11:35: 11:36 error: use of moved value: `x`
borrow.rs:11 println!("Value of x is {}",x);
^
note: in expansion of format_args!
<std macros>:2:25: 2:58 note: expansion site
<std macros>:1:1: 2:62 note: in expansion of print!
<std macros>:3:1: 3:54 note: expansion site
<std macros>:1:1: 3:58 note: in expansion of println!
borrow.rs:11:7: 11:38 note: expansion site
borrow.rs:8:11: 8:12 note: `x` moved here because it has type `Box<i32>`,
which is moved by default
borrow.rs:8 let y = x;
^
borrow.rs:8:12: 8:12 help: use `ref` to override
error: aborting due to previous error
yのlifetime
example5.rs (メモリー管
理)fn main() {
let x = Box::new(4);
println!("Value of x is {}",x);
if true {
let y = x;
println!("Value of y is {}",y);
x = y;
}
println!("Value of x is {}",x);
}
borrow.rs:11:35: 11:36 error: use of moved value: `x`
borrow.rs:11 println!("Value of x is {}",x);
^
note: in expansion of format_args!
<std macros>:2:25: 2:58 note: expansion site
<std macros>:1:1: 2:62 note: in expansion of print!
<std macros>:3:1: 3:54 note: expansion site
<std macros>:1:1: 3:58 note: in expansion of println!
borrow.rs:11:7: 11:38 note: expansion site
borrow.rs:8:11: 8:12 note: `x` moved here because it has type `Box<i32>`,
which is moved by default
borrow.rs:8 let y = x;
^
borrow.rs:8:12: 8:12 help: use `ref` to override
error: aborting due to previous error
example5.rs (メモリー管
理)fn main() {
let mut x = Box::new(4);
println!("Value of x is {}",x);
if true {
let y = x;
println!("Value of y is {}",y);
x = y;
}
println!("Value of x is {}",x);
}
Value of x is 4
Value of y is 4
Value of x is 4
メモリー管理 - move
x x
y
以上 。。。?

More Related Content

PDF
Rust concurrency tutorial 2015 12-02
PDF
Rust Mozlando Tutorial
PDF
Introduction to Rust
PPTX
Introduction to Rust language programming
PDF
Rust tutorial from Boston Meetup 2015-07-22
PDF
The Rust Programming Language: an Overview
PDF
Why rust?
Rust concurrency tutorial 2015 12-02
Rust Mozlando Tutorial
Introduction to Rust
Introduction to Rust language programming
Rust tutorial from Boston Meetup 2015-07-22
The Rust Programming Language: an Overview
Why rust?

What's hot (20)

PDF
Clojure 1.1 And Beyond
PDF
Rust: Unlocking Systems Programming
PDF
The Magnificent Seven
PDF
NativeBoost
PPTX
Grand Central Dispatch in Objective-C
PDF
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
DOCX
Oops pramming with examples
PDF
The Ring programming language version 1.5.3 book - Part 25 of 184
PPTX
Python
PDF
JavaScript - new features in ECMAScript 6
PDF
Php engine
PDF
Ownership System in Rust
PDF
Protocol handler in Gecko
PPT
C++totural file
PPT
PDF
Coroutines in Kotlin. UA Mobile 2017.
PDF
Create your own PHP extension, step by step - phpDay 2012 Verona
PPTX
Groovy
PDF
ES2015 (ES6) Overview
PDF
Code Generation in PHP - PHPConf 2015
Clojure 1.1 And Beyond
Rust: Unlocking Systems Programming
The Magnificent Seven
NativeBoost
Grand Central Dispatch in Objective-C
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Oops pramming with examples
The Ring programming language version 1.5.3 book - Part 25 of 184
Python
JavaScript - new features in ECMAScript 6
Php engine
Ownership System in Rust
Protocol handler in Gecko
C++totural file
Coroutines in Kotlin. UA Mobile 2017.
Create your own PHP extension, step by step - phpDay 2012 Verona
Groovy
ES2015 (ES6) Overview
Code Generation in PHP - PHPConf 2015
Ad

Viewers also liked (18)

PDF
Rust言語
PDF
Rust 超入門
PDF
Rust 1.0 Release記念祝賀 - Rustのドキュメントを少し訳してみた
PDF
パワポアート・オンライン
PDF
ODP
プログラミング言語のマスコットとか紹介
PDF
夢のある話をしようと思ったけど、やっぱり現実の話をする
PDF
Smaltalk驚異の開発(私が使い続ける2012年の話)
PDF
今日から使おうSmalltalk
PDF
「再代入なんて、あるわけない」 ~ふつうのプログラマが関数型言語を知るべき理由~ (Gunma.web #5 2011/05/14)
PDF
C++の黒魔術
PDF
Rust v1.0 release celebration party
PDF
たのしい高階関数
PDF
C++の話(本当にあった怖い話)
PDF
磯野ー!関数型言語やろうぜー!
PDF
数学プログラムを Haskell で書くべき 6 の理由
PDF
RustなNATSのClientを作ってみた
Rust言語
Rust 超入門
Rust 1.0 Release記念祝賀 - Rustのドキュメントを少し訳してみた
パワポアート・オンライン
プログラミング言語のマスコットとか紹介
夢のある話をしようと思ったけど、やっぱり現実の話をする
Smaltalk驚異の開発(私が使い続ける2012年の話)
今日から使おうSmalltalk
「再代入なんて、あるわけない」 ~ふつうのプログラマが関数型言語を知るべき理由~ (Gunma.web #5 2011/05/14)
C++の黒魔術
Rust v1.0 release celebration party
たのしい高階関数
C++の話(本当にあった怖い話)
磯野ー!関数型言語やろうぜー!
数学プログラムを Haskell で書くべき 6 の理由
RustなNATSのClientを作ってみた
Ad

Similar to Rust言語紹介 (20)

PDF
Javascript status 2016
PDF
Python and rust 2018 pythonkorea jihun
KEY
Writing robust Node.js applications
PPT
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
PDF
What To Expect From PHP7
PPTX
Androsia: A step ahead in securing in-memory Android application data by Sami...
PDF
Google maps
PPT
Php basic for vit university
PDF
ES6: The Awesome Parts
KEY
Let's build a parser!
PDF
node.js, javascript and the future
PPTX
Ch1(introduction to php)
PDF
Seaside - The Revenge of Smalltalk
PPTX
ES6 is Nigh
PDF
The_Borrow_Checker.pdf
PDF
React Native Evening
PDF
extending-php
PDF
extending-php
PDF
extending-php
PDF
extending-php
Javascript status 2016
Python and rust 2018 pythonkorea jihun
Writing robust Node.js applications
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
What To Expect From PHP7
Androsia: A step ahead in securing in-memory Android application data by Sami...
Google maps
Php basic for vit university
ES6: The Awesome Parts
Let's build a parser!
node.js, javascript and the future
Ch1(introduction to php)
Seaside - The Revenge of Smalltalk
ES6 is Nigh
The_Borrow_Checker.pdf
React Native Evening
extending-php
extending-php
extending-php
extending-php

More from Paweł Rusin (8)

PDF
Workflow and development in globally distributed mobile teams
ODP
LOD METI
ODP
R言語で統計分類基本
ODP
関東第3回ゼロはじめるからR言語勉強会ー グラフ
ODP
関東第2回r勉強会
ODP
課題 (第三回)
ODP
第三回R勉強会
ODP
第2回R勉強会1
Workflow and development in globally distributed mobile teams
LOD METI
R言語で統計分類基本
関東第3回ゼロはじめるからR言語勉強会ー グラフ
関東第2回r勉強会
課題 (第三回)
第三回R勉強会
第2回R勉強会1

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
KodekX | Application Modernization Development
PPTX
MYSQL Presentation for SQL database connectivity
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Cloud computing and distributed systems.
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Unlocking AI with Model Context Protocol (MCP)
KodekX | Application Modernization Development
MYSQL Presentation for SQL database connectivity
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Machine learning based COVID-19 study performance prediction
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Spectral efficient network and resource selection model in 5G networks
Big Data Technologies - Introduction.pptx
Cloud computing and distributed systems.
Reach Out and Touch Someone: Haptics and Empathic Computing
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Empathic Computing: Creating Shared Understanding
Encapsulation_ Review paper, used for researhc scholars
Agricultural_Statistics_at_a_Glance_2022_0.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Encapsulation theory and applications.pdf

Rust言語紹介