Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rust tutorial for Pythonista
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Kentaro Matsumoto
March 10, 2022
Programming
2
1.4k
Rust tutorial for Pythonista
Start Python Club 20220310 Pythonistaに送るRust入門
Kentaro Matsumoto
March 10, 2022
Tweet
Share
More Decks by Kentaro Matsumoto
See All by Kentaro Matsumoto
claude_code.pdf
matsu7874
5
7.3k
Marpを使って登壇資料を作る
matsu7874
0
2k
Generate a rust client code by OpenAPI Generator
matsu7874
0
660
ざっと理解するRust 2024 Edition
matsu7874
0
1.7k
プリントデバッグを失敗させないテクニック
matsu7874
1
430
社外を巻き込んだ勉強会を定期開催するコツ
matsu7874
0
220
actix-webを使った開発のハマリポイントを避けたい
matsu7874
0
1.2k
our test strategy on actix-web app
matsu7874
0
1.7k
roadmap to rust 2024
matsu7874
0
2.2k
Other Decks in Programming
See All in Programming
24時間止められないシステムを守る-医療ITにおけるランサムウェア対策の実際
koukimiura
2
170
プロダクトオーナーから見たSOC2 _SOC2ゆるミートアップ#2
kekekenta
0
250
AI巻き込み型コードレビューのススメ
nealle
2
2.1k
Head of Engineeringが現場で回した生産性向上施策 2025→2026
gessy0129
PRO
0
180
AWS re:Invent 2025参加 直前 Seattle-Tacoma Airport(SEA)におけるハードウェア紛失インシデントLT
tetutetu214
2
120
AIプロダクト時代のQAエンジニアに求められること
imtnd
1
430
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
210
組織で育むオブザーバビリティ
ryota_hnk
0
190
PJのドキュメントを全部Git管理にしたら、一番喜んだのはAIだった
nanaism
0
190
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
1.7k
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
330
NetBSD+Raspberry Piで 本物のPSGを鳴らすデモを OSC駆動の7日間で作った話 / OSC2026Osaka
tsutsui
1
120
Featured
See All Featured
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
750
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.7k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
0
210
For a Future-Friendly Web
brad_frost
182
10k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
The Limits of Empathy - UXLibs8
cassininazir
1
230
A Modern Web Designer's Workflow
chriscoyier
698
190k
Side Projects
sachag
455
43k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
200
Fireside Chat
paigeccino
41
3.8k
Designing for Timeless Needs
cassininazir
0
140
Transcript
Rust tutorial for Pythonista @matsu7874 2022.3.10 Start Python Club みんなのPython勉強会#79
自己紹介 • 松本健太郎 (Kentaro MATSUMOTO) @matsu7874 • ソフトウェアエンジニア@フォルシア株式会社 ◦ Rustでインメモリデータベースを開発
◦ 技術広報・エンジニア採用 • 興味 ◦ Webアプリケーション ◦ 技術広報・エンジニア採用 ◦ 競技プログラミング • #stapy で感想をツイートしてね! 2
目次 • まずはRustを書いてみる。 • Rustってどんな言語 • 所有権(ownership) • ライフタイム(生存期間, lifetime)
• パターンマッチ • Cargo • Python と Rust を使う • 日本語のコミュニティ・資料など 3
Rust書いたことありますか? はい・いいえ 4
5 はじめてのRustプログラム 1. 「Rust Playground」と検索して https://play.rust-lang.org/ にアクセスしてください。 2. 下記のプログラムを入力して「RUN▶」を押してみましょう。
画面右側に「We love Python and Rust.」と表示されれば成功です。
Rust書いたことありますか? はい・いいえ 6
7 環境構築 1. https://rustup.rs/ にアクセスしてください。 2. 環境に応じてインストールの案内が表示されます a.
Linux系の場合は下記のコマンドを実行するだけでインストール完了です。
8 コンパイルして実行 (rustcの場合) 1. main.rs にプログラムを書く 2. rustc でコンパイルする
3. main.out を実行する
9 コンパイルして実行 (cargoの場合) 1. cargo new で新しいプロジェクトを作成 2. main.rs
にプログラムを書く 3. cargo runでコンパイル・実行
10 Rustってどんな言語 6年連続開発者から愛されている言語 1位 https://insights.stackoverflow.com/survey/2021#most-loved-dreaded-and-wanted-language-love-dread
11 Rustってどんな言語 高速で安全で生産性の高い言語 https://www.rust-lang.org/ja
12 Rustのパフォーマンス RustはC++と同程度に高速、Pythonの約30倍高速。 https://benchmarksgame-team.pages.debian.net/benchmarksgame/box-plot-summary-charts.html
13 Rustの信頼性 型システムと所有権によるコンパイル時の検証 • 安全ではないコードを無自覚にかけない仕組み
14 Rustの生産性 • ドキュメントの充実 • コンパイラのエラーメッセージが親切 • 標準インストールのパッケージマネージャ・ビルドツール・フォーマッタ
• ランゲージサーバ https://www.rust-lang.org/learn Python Rust package manager pip, poetry cargo language server Pylance rust-analyzer formatter autopep8, black rustfmt linter Pylint, flake8 clippy
15 所有権:Rustの信頼性の要 アイデア:所有権って概念を入れればGCを使わなくてもメモリ管理できるぞ!
16 所有権:変数とメモリ上の値の対応関係 メモリ上の値は唯一の所有者と呼ばれる変数を持つ 所有者である変数がスコープから外れた時、メモリを開放して良い x y vec![1,2,3]
x vec![1,2,3]
17 ライフタイム:参照が安全に使える範囲 毎回所有権が移動してはプログラミングしにくい。一時的に所有権を借りる(参照)ことができる。 この参照を安全に利用できる期間がライフタイム(生存期間)と呼ばれるもの。
18 しれっとヤバいコードを許さない
19 パターンマッチ: matchの腕 https://doc.rust-lang.org/rust-by-example/flow_control/match.html
20 パターンマッチ: 分割代入
21 パターンマッチ: if let は match の置き換え
22 パターンマッチ: while let は loop{match} の置き換え
23 Cargo: 標準のパッケージマネージャ • 標準だからみんなこれを使っている • よく使うコマンド ◦ cargo
new: パッケージを新しく作る ◦ cargo check: コンパイルせずに文法や依存関係のチェックを行う ◦ cargo build: コンパイルする ◦ cargo run: 実行する ◦ cargo run --release: リリースビルド(高速)で実行する ◦ cargo fmt: コード整形(標準搭載なので悩まなくて良い) ◦ cargo clippy: linter、Rustっぽい書き方も教えてくれる。
24 clippy https://rust-lang.github.io/rust-clippy/master/
25 Python と Rust を使う • 既存資産使えます。 ◦ PyO3という非常に簡単にバインディングを行えるライブラリがあります。
◦ https://github.com/PyO3/pyo3#using-rust-from-python • Pythonが強い領域でRustを使おうとしている人たちもいます。 ◦ 速度の高みを目指す:高速な単語分割器 Vaporetto の技術解説 ▪ https://tech.legalforce.co.jp/entry/2021/09/28/180844 ◦ 日本語形態素解析器 Sudachi のRust実装 ▪ https://github.com/WorksApplications/sudachi.rs
26 日本語のコミュニティ • rust-jp slack https://rust-jp.rs/ • イベント
◦ Shinjuku.rs https://forcia.connpass.com/ ◦ Rust LT https://rust.connpass.com/ ◦ Rustオンラインもくもく会 https://rust-online.connpass.com/ ◦ Rust.Tokyo 年1回のカンファレンス https://rust.tokyo/
27 日本語のオンラインドキュメント • Rustの日本語ドキュメント https://doc.rust-jp.rs/ • とほほのRust入門 https://www.tohoho-web.com/ex/rust.html
28 日本語のおすすめ書籍 • 実践Rust入門[言語仕様から開発手法まで] (2019/5/8) ◦ それまで雰囲気で書いていた部分が理解できました。 •
実践Rustプログラミング入門 (2020/8/22) ◦ いろいろな題材をRustで書いてみる本です。共著者として参加。 • コンセプトから理解するRust (2022/2/12) ◦ 比較的薄く、メモリレイアウトが理解しやすい。
Rust も いいぞ! @matsu7874 29