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
97
Swiftコードバトル必勝法
toshi0383
1
200
Sheets API使ってみた
toshi0383
2
250
visionOSについてGlobeeが取り組んでいること
toshi0383
0
430
agile20150512-150512055145-lva1-app6892.pdf
toshi0383
0
120
たのしいAirPlay
toshi0383
1
660
Profiling using Signpost
toshi0383
2
870
AVPlayer周りの設計tips
toshi0383
6
810
AbemaTV iOSのダウンロード再生機能
toshi0383
4
940
Other Decks in Programming
See All in Programming
Contemporary Test Cases
maaretp
0
140
Jakarta EE meets AI
ivargrimstad
0
690
Functional Event Sourcing using Sekiban
tomohisa
0
100
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.2k
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
130
Macとオーディオ再生 2024/11/02
yusukeito
0
370
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
690
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
240
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
RubyLSPのマルチバイト文字対応
notfounds
0
120
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Facilitating Awesome Meetings
lara
50
6.1k
Code Reviewing Like a Champion
maltzj
520
39k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Become a Pro
speakerdeck
PRO
25
5k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Producing Creativity
orderedlist
PRO
341
39k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
What's new in Ruby 2.0
geeforr
343
31k
It's Worth the Effort
3n
183
27k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
How to train your dragon (web standard)
notwaldorf
88
5.7k
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