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
cmdshelf::from("Swift")
Search
toshi0383
September 05, 2018
Programming
3
840
cmdshelf::from("Swift")
RustのLT会! Rust入門者の集い #5 の発表資料です。
https://rust.connpass.com/event/92821/
toshi0383
September 05, 2018
Tweet
Share
More Decks by toshi0383
See All by toshi0383
CoreDataはじめました
toshi0383
0
100
Swiftコードバトル必勝法
toshi0383
1
220
Sheets API使ってみた
toshi0383
2
270
visionOSについてGlobeeが取り組んでいること
toshi0383
0
440
agile20150512-150512055145-lva1-app6892.pdf
toshi0383
0
140
たのしいAirPlay
toshi0383
1
670
Profiling using Signpost
toshi0383
2
880
AVPlayer周りの設計tips
toshi0383
6
820
AbemaTV iOSのダウンロード再生機能
toshi0383
4
940
Other Decks in Programming
See All in Programming
MCP with Cloudflare Workers
yusukebe
2
220
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
Security_for_introducing_eBPF
kentatada
0
110
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
ドメインイベント増えすぎ問題
h0r15h0
1
230
From Translations to Multi Dimension Entities
alexanderschranz
2
130
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
770
CSC509 Lecture 14
javiergs
PRO
0
140
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
testcontainers のススメ
sgash708
1
120
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
210
Featured
See All Featured
KATA
mclloyd
29
14k
Navigating Team Friction
lara
183
15k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
A Philosophy of Restraint
colly
203
16k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Being A Developer After 40
akosma
87
590k
Building Your Own Lightsaber
phodgson
103
6.1k
Building Applications with DynamoDB
mza
91
6.1k
Code Reviewing Like a Champion
maltzj
520
39k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Transcript
Swi!Ͱॻ͍ͨCLIπʔϧΛRustͰ ॻ͖͠·ͨ͠ RustͷLTձʂ Rustೖऀͷू͍ #5 Sep 5, 2018 Toshihiro Suzuki
© Toshihiro Suzuki 2018 1
whoami ླ ढ़༟ (@toshi0383 / τογʔ) 2011- SRAͱ͍͏ձࣾ UnixͰJava 2014-
ωΫετεέʔϓͱ͍͏ձࣾͰiOSσϏϡʔ, DRMΤʔδΣϯτSDKͪΐͬͱ͚ͩܦݧ. 2017- AbemaTV join. iOSDCͰLTͨ͠ΓɺtvOSΞυϕϯτΧϨϯμʔओ࠵ͨ͠Γ. 2018- ಈըμϯϩʔυػೳΛ࣮. ݱࡏετϦʔϛϯάΫϥΠΞϯτνʔϜͰಈըࢹௌମݧ্ ศརͳπʔϧΛ࡞ͬͯ։ൃΛޮԽ͢Δͷ͕झຯ ϨʔγϯάΧʔτܦݧऀ, GT SPORT, F1 Rustྺ1ϲ݄͘Β͍ (ॳ৺ऀͰ͢ʂ) © Toshihiro Suzuki 2018 2
Swi!Ͱॻ͍͍ͯͨπʔϧ cmdshelf © Toshihiro Suzuki 2018 3
cmdshelfͱ εΫϦϓτϚωʔδϟʔ, ίϚϯυϥϯφʔ — scriptΛஔ͍ͨgit repoΛremoteͱͯ͠ొ — cmdshelf run hoge/bar.sh
ͱ࣮ͯ͠ߦͰ͖Δ — $PATH ͷઃఆ͕ෆཁ σΟϨΫτϦͰωʔϜεϖʔεΛΕΔ — iOS/tvOSνʔϜؒͷڞ௨scriptӡ༻͕՝ͩͬͨ © Toshihiro Suzuki 2018 4
ઌि·ͰSwi! (ͱC) Ͱ͕ͨ͠.. © Toshihiro Suzuki 2018 5
RustʹແࣄҠߦྃ͠·ͨ͠ ! © Toshihiro Suzuki 2018 6
ͳͥRustʹҠߦͨ͠ͷ͔ ʮͦΕͳΓʹStar ⭐ ͍͖ͭͯͨ͠ɺͦΖͦΖͪΌΜͱcross- platformରԠ͍ͨ͠ͳʔʯ — Swiftͩͱ΄΅AppleΤίγεςϜͰ͔͠ಈ͔ͳ͍ɻ — SwiftΤίγεςϜతʹCLIπʔϧॻ͘ͷʹ͍ͯͳ͍ؾ͕ ͖ͯͨ͠ɻ(ޙड़)
ݸਓతʹΑ͍ͬͯ͘Δ sharkdp/fd ͕RustͰॻ͔Ε͍ͯͯɺ લ͔ΒRustͬͯΈ͍ͨͱࢥ͍ͬͯͨɻ © Toshihiro Suzuki 2018 7
࣮ࡍʹRustͰॻ͍ͯΈͯΑ͔ͬͨ ͱ͜Ζ © Toshihiro Suzuki 2018 8
(ୈҰҹ) Cargo.toml؆ܿͰྑͦ͞͏ɻ Package.swift, build.gradle, Fastfile ͳͲɺߴػೳͳઃఆ ϑΝΠϧʹίʔυΛॻ͍ͯ͠·͍ෳࡶԽ͕ͪ͠ɻ ͦΕ͕Ͱ͖ͳ͍ͷ͕ྑͦ͞͏ɻ > Why
cargo use toml? > It's basically the least terrible option © Toshihiro Suzuki 2018 9
֎෦ίϚϯυ࣮ߦͷ࣮͕͍͢͠ ίϚϯυ࣮ߦ cmdshelf ʹͱͬͯ৺ଁ෦ std::process::Command let output = if cfg!(target_os
= "windows") { Command::new("cmd") .args(&["/C", command]) .output() } else { Command::new("sh") .arg("-c") .arg(command) .output() }; © Toshihiro Suzuki 2018 10
Swi!ͩͱ࣮͜ͷล͕Ұ൪ͭΒ͍ Foundation͔ΒPOSIXܥͷAPI͕͍ͭͷؒʹ͔Ұ෦remove͞ Ε͍ͯͨࣄ݅ɻFoundation.ProcessΛ͑ͱͷ͜ͱɻ Foundation.ProcessΠϯλʔϑΣʔε͕Θ͔ΓͮΒ͘ඪ४ ೖग़ྗͷڍಈΛҙਤ௨Γ࣮Ͱ͖ͣɺ݁ہpopenpcloseΛC Ͱ࠶࣮ ! © Toshihiro Suzuki
2018 11
CLIϫʔΩϯάάϧʔϓ ! ࠓ(2018)3݄ʹΩοΫΦϑ Announcing the CLI Working Group "Command Line
Application in Rust" (CLAIR) book! (WIP) CLIπʔϧ࣮ͷΨΠυϥΠϯυΩϡϝϯτ͕ࡦఆ͞Ε͍ͯ Δɻ ࠓޙͷൃలʹظ͕࣋ͯͦ͏ɻ © Toshihiro Suzuki 2018 12
CLI Dev UX͕ྑͦ͞͏ © Toshihiro Suzuki 2018 13
CLIπʔϧ։ൃऀઢͰͷSwi!ͱͷൺֱ(શʹओ؍) ػೳ Swi! Rust ։ൃڥ Xcode, vim vim ύοέʔδཧ SwiftPM
Cargo ύοέʔδఆٛ Package.swift Cargo.toml ઃఆϑΝΠϧ yml toml(?) ύοέʔδϚωʔδϟͷman ϖʔδαϙʔτ ͳ͍͢͠Δؾͳͦ͞͏ ͳ͍͚Ͳrfcͱͯٞ͠͞Εͯ ͍Δ ֎෦ίϚϯυ࣮ߦ Foundation.Process or ඇਪ ͳPOSIX API(ڪා) std::process::Command © Toshihiro Suzuki 2018 14
࣮ͰϋϚͬͨͱ͜Ζ © Toshihiro Suzuki 2018 15
τϨΠτΦϒδΣΫτฦͤ·ͤΜ — impl Runnable ฦͤ·ͤΜʂ — Box<Runnable + 'static> ͳΜͩ͜Ε
© Toshihiro Suzuki 2018 16
String ͷlifetime parameter? pub struct CommandEntry<'a> { pub remote: &'a
str, pub fullpath: String, pub path: &'a str, // fullpathͷҰ෦ } ॳظԽ࣌ʹ fullpath ͱ path ͷੜଘظؒΛඥ͚ͮΔ͜ͱ͕Ͱ ͖ͣίϯύΠϧ௨Βͣ ! © Toshihiro Suzuki 2018 17
String ͷlifetime parameter? ຖճܭࢉͤͯ͞ճආ pub struct CommandEntry<'a> { pub remote:
&'a str, pub fullpath: String, } impl<'a> CommandEntry<'a> { pub fn path(&self) -> &str { ... } } ͍͍ํ๏͋Εͥͻڭ͍͑ͯͩ͘͞ © Toshihiro Suzuki 2018 18
٤ۓͷ՝ © Toshihiro Suzuki 2018 19
٤ۓͷ՝ ΫϩεϓϥοτϑΥʔϜରԠ © Toshihiro Suzuki 2018 20
٤ۓͷ՝ ΫϩεϓϥοτϑΥʔϜରԠ Windows࣋ͬͯͳ͍͠ɺmacOSҎ֎΄ͱΜͲ৮ͬͨ͜ͱͳ ͍ɻ Έͳ͞ΜͲ͏ͯ͠Δͷʁ © Toshihiro Suzuki 2018 21
ಉٙ͡Λ͍࣋ͬͯΔਓ͕ͨ·ͨ·CLI-WGͷGi!erͰ࣭͠ ͯͨ © Toshihiro Suzuki 2018 22
CLI-WGతʹͪ͜ΒͰٞ͞Ε͍ͯΔ༷ɻ - rust-lang-nursery/cli-wg#8 ͱΓ͋͑ͣ japaric/trust Ͱ֤ϓϥοτϑΥʔϜ͚ͷόΠφ Ϧ࡞Εͦ͏ʁ © Toshihiro Suzuki
2018 23
Ҏલʹ ϑΝΠϧύε۠จࣈͷߟྀΕͯͨ path.split("/") => ࡢରԠ͠·ͨ͠ɻ ଞʹ͍Ζ͍ΖରԠඞཁͳͷ͔ɻ © Toshihiro Suzuki 2018
24
summary — RustCLIπʔϧͷDev UX͕ྑͦ͞͏ɻ — ൃද·ͰʹҠߦؒʹ߹ͬͯΑ͔ͬͨɻ — ϓϧϦΫܴɻಛʹɺ৽ϩΰඳ͍ͯ͘ΕΔਓืू © Toshihiro
Suzuki 2018 25
Toshihiro Suzuki ! Twitter: @toshi0383 GitHub: @toshi0383 Qiita: @toshi0383 Email:
[email protected]
© Toshihiro Suzuki 2018 26