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
830
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
94
Swiftコードバトル必勝法
toshi0383
1
200
Sheets API使ってみた
toshi0383
2
250
visionOSについてGlobeeが取り組んでいること
toshi0383
0
420
agile20150512-150512055145-lva1-app6892.pdf
toshi0383
0
120
たのしいAirPlay
toshi0383
1
650
Profiling using Signpost
toshi0383
2
870
AVPlayer周りの設計tips
toshi0383
6
810
AbemaTV iOSのダウンロード再生機能
toshi0383
4
940
Other Decks in Programming
See All in Programming
Realtime API 入門
riofujimon
0
110
C#/.NETのこれまでのふりかえり
tomokusaba
1
160
ECSのサービス間通信 4つの方法を比較する 〜Canary,Blue/Greenも添えて〜
tkikuc
11
2.3k
デプロイを任されたので、教わった通りにデプロイしたら障害になった件 ~俺のやらかしを越えてゆけ~
techouse
52
32k
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
350
/←このスケジュール表に立ち向かう フロントエンド開発戦略 / A front-end development strategy to tackle a single-slash schedule.
nrslib
1
590
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
270
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
200
Piniaの現状と今後
waka292
5
1.5k
Java ジェネリクス入門 2024
nagise
0
610
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
210
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
250
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Code Review Best Practice
trishagee
64
17k
Thoughts on Productivity
jonyablonski
67
4.3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
Testing 201, or: Great Expectations
jmmastey
38
7k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Into the Great Unknown - MozCon
thekraken
31
1.5k
GraphQLの誤解/rethinking-graphql
sonatard
66
10k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
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