SlideShare a Scribd company logo
1 of 13
Download to read offline
Rust 超入門 
Chris Birchall @ M3 
2014/10/28 
#learnrust_jp
今日の流れ 
19:00〜Rust紹介 
19:30〜20:30 ゲームを作ってみよう! 
20:30〜成果・感想・質問・雑談 
21:00 おしまい
About me 
● Scalaおじさん 
● 流行りのGolangが気に入らない 
● 本を買ってください(ドヤ 
manning.com/birchall
Rust 
● Mozilla発(2009年頃〜) 
● システムプログラミング言語 
○ バイナリにコンパイルされる 
○ 速い 
○ ポインター 
○ GC無し 
● 関数型っぽい機能もある 
○ パターンマッチ 
○ クロージャー 
○ Algebraic Data Types 
○ 型推論
ドキュメントがすごすぎる件
Hello, world! 
fn main() { 
println!("Hello, world!"); 
} 
$ rustc hello.rs 
$ ./hello 
Hello, world!
Algebraic Data Types 
● タプル 
● Struct 
● Enum 
enum Expr { 
Number(int), 
Plus(Expr, Expr), 
Minus(Expr, Expr), 
Mult(Expr, Expr), 
Div(Expr, Expr), 
}
状態/副作用の管理が面白い 
● 変数はデフォルトで immutable 
let mut a = 5i; 
● データの所有という概念がある 
○ 作った人が所有者 
○ 所有している物を人に貸すことができる 
■ Ex: 関数に渡す時 
○ mutable と immutable な貸し出し 
○ コンパイラがルールをチェックする
並列処理 
● Taskをspawnする 
● Taskが参照する変数の所有者になる 
○ メインスレッドで参照できなくなる 
● Channelを使ってTaskとやり取りする 
● Futureもある 
let (tx, rx) = channel(); 
spawn(proc() { 
tx.send(" タスクだよーん".to_string()); 
}); 
let message = rx.recv(); 
println!("{}", message);
Crate と Module 
● Crate = コンパイルの単位 
○ 1個のCrateをコンパイルして1個のライブラリ又 
はプログラムが出来上がる 
● 他のCrateに依存できる 
● Crate内にModuleを作れる 
● Moduleはpublicな関数をexportする 
mod hello { 
pub fn print_hello() { 
println!("Hello, world!"); 
} 
}
Cargo 
● ビルドツール 
● 依存性管理 
# Cargo.toml 
[package] 
name = "hello" 
version = "0.0.1" 
authors = [ "Chris Birchall <c-birchall@m3.com>" ] 
[[bin]] 
name = "hello"
気になるとこ、その他 
● traitは型クラスである 
● マクロがある 
● ポインターがある(こわい) 
● Stringが2種類ある 
● ScalaのIterateesに近い物がある 
○ Iterator, iterator adapter, consumer 
● 無限ループ用のキーワードがある(loop)
ゲームを作ってみよう 
初級:あっち向いてホイ! 
中級:数字推測ゲーム 
上級:オセロ 
目標 
● ゲームが動く! 
● 標準ライブラリを使う 
● Cargoを使う。外部dependencyを使う 
● Crateとしてパッケージする

More Related Content

What's hot (6)

Rk10trailer
Rk10trailerRk10trailer
Rk10trailer
 
レガシーシステムのDBマイグレーションし始めた話
レガシーシステムのDBマイグレーションし始めた話レガシーシステムのDBマイグレーションし始めた話
レガシーシステムのDBマイグレーションし始めた話
 
Rubyで連結リスト使うためのgemを作った(tsukuba.rb版)
Rubyで連結リスト使うためのgemを作った(tsukuba.rb版)Rubyで連結リスト使うためのgemを作った(tsukuba.rb版)
Rubyで連結リスト使うためのgemを作った(tsukuba.rb版)
 
Sbブレスト会議 4 30
Sbブレスト会議 4 30Sbブレスト会議 4 30
Sbブレスト会議 4 30
 
Hokkaido.pm.casual #03 slide
Hokkaido.pm.casual #03 slideHokkaido.pm.casual #03 slide
Hokkaido.pm.casual #03 slide
 
Aizu lt tokyo_luxion
Aizu lt tokyo_luxionAizu lt tokyo_luxion
Aizu lt tokyo_luxion
 

More from Chris Birchall

Tour of distributed systems 1 - ZooKeeper
Tour of distributed systems 1 - ZooKeeperTour of distributed systems 1 - ZooKeeper
Tour of distributed systems 1 - ZooKeeper
Chris Birchall
 
Load testing with gatling
Load testing with gatlingLoad testing with gatling
Load testing with gatling
Chris Birchall
 
Debugging and Testing ES Systems
Debugging and Testing ES SystemsDebugging and Testing ES Systems
Debugging and Testing ES Systems
Chris Birchall
 

More from Chris Birchall (11)

Scala.js & friends: SCALA ALL THE THINGS
Scala.js & friends: SCALA ALL THE THINGSScala.js & friends: SCALA ALL THE THINGS
Scala.js & friends: SCALA ALL THE THINGS
 
Tour of Distributed Systems 3 - Apache Kafka
Tour of Distributed Systems 3 - Apache KafkaTour of Distributed Systems 3 - Apache Kafka
Tour of Distributed Systems 3 - Apache Kafka
 
Tour of distributed systems 2 - Cassandra
Tour of distributed systems 2 - CassandraTour of distributed systems 2 - Cassandra
Tour of distributed systems 2 - Cassandra
 
Guess the Country - Playing with Twitter Streaming API
Guess the Country - Playing with Twitter Streaming APIGuess the Country - Playing with Twitter Streaming API
Guess the Country - Playing with Twitter Streaming API
 
Tour of distributed systems 1 - ZooKeeper
Tour of distributed systems 1 - ZooKeeperTour of distributed systems 1 - ZooKeeper
Tour of distributed systems 1 - ZooKeeper
 
ScalaCache: simple caching in Scala
ScalaCache: simple caching in ScalaScalaCache: simple caching in Scala
ScalaCache: simple caching in Scala
 
Hydra
HydraHydra
Hydra
 
Load testing with gatling
Load testing with gatlingLoad testing with gatling
Load testing with gatling
 
Debugging and Testing ES Systems
Debugging and Testing ES SystemsDebugging and Testing ES Systems
Debugging and Testing ES Systems
 
Phone Home: A client-side error collection system
Phone Home: A client-side error collection systemPhone Home: A client-side error collection system
Phone Home: A client-side error collection system
 
Branching Strategies: Feature Branches vs Branch by Abstraction
Branching Strategies: Feature Branches vs Branch by AbstractionBranching Strategies: Feature Branches vs Branch by Abstraction
Branching Strategies: Feature Branches vs Branch by Abstraction
 

Recently uploaded

Recently uploaded (11)

Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 

Rust 超入門

  • 1. Rust 超入門 Chris Birchall @ M3 2014/10/28 #learnrust_jp
  • 2. 今日の流れ 19:00〜Rust紹介 19:30〜20:30 ゲームを作ってみよう! 20:30〜成果・感想・質問・雑談 21:00 おしまい
  • 3. About me ● Scalaおじさん ● 流行りのGolangが気に入らない ● 本を買ってください(ドヤ manning.com/birchall
  • 4. Rust ● Mozilla発(2009年頃〜) ● システムプログラミング言語 ○ バイナリにコンパイルされる ○ 速い ○ ポインター ○ GC無し ● 関数型っぽい機能もある ○ パターンマッチ ○ クロージャー ○ Algebraic Data Types ○ 型推論
  • 6. Hello, world! fn main() { println!("Hello, world!"); } $ rustc hello.rs $ ./hello Hello, world!
  • 7. Algebraic Data Types ● タプル ● Struct ● Enum enum Expr { Number(int), Plus(Expr, Expr), Minus(Expr, Expr), Mult(Expr, Expr), Div(Expr, Expr), }
  • 8. 状態/副作用の管理が面白い ● 変数はデフォルトで immutable let mut a = 5i; ● データの所有という概念がある ○ 作った人が所有者 ○ 所有している物を人に貸すことができる ■ Ex: 関数に渡す時 ○ mutable と immutable な貸し出し ○ コンパイラがルールをチェックする
  • 9. 並列処理 ● Taskをspawnする ● Taskが参照する変数の所有者になる ○ メインスレッドで参照できなくなる ● Channelを使ってTaskとやり取りする ● Futureもある let (tx, rx) = channel(); spawn(proc() { tx.send(" タスクだよーん".to_string()); }); let message = rx.recv(); println!("{}", message);
  • 10. Crate と Module ● Crate = コンパイルの単位 ○ 1個のCrateをコンパイルして1個のライブラリ又 はプログラムが出来上がる ● 他のCrateに依存できる ● Crate内にModuleを作れる ● Moduleはpublicな関数をexportする mod hello { pub fn print_hello() { println!("Hello, world!"); } }
  • 11. Cargo ● ビルドツール ● 依存性管理 # Cargo.toml [package] name = "hello" version = "0.0.1" authors = [ "Chris Birchall <c-birchall@m3.com>" ] [[bin]] name = "hello"
  • 12. 気になるとこ、その他 ● traitは型クラスである ● マクロがある ● ポインターがある(こわい) ● Stringが2種類ある ● ScalaのIterateesに近い物がある ○ Iterator, iterator adapter, consumer ● 無限ループ用のキーワードがある(loop)
  • 13. ゲームを作ってみよう 初級:あっち向いてホイ! 中級:数字推測ゲーム 上級:オセロ 目標 ● ゲームが動く! ● 標準ライブラリを使う ● Cargoを使う。外部dependencyを使う ● Crateとしてパッケージする