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
Go言語でターミナルフレンドリーなAIコマンド、afaを作った/fukuokago20_afa
monochromegane
2
140
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
250
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
200
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
480
推し活としてのrails new/oshikatsu_ha_iizo
sakahukamaki
3
1.7k
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
210
Vue3の一歩踏み込んだパフォーマンスチューニング2024
hal_spidernight
3
3.1k
Android 15 でアクションバー表示時にステータスバーが白くなってしまう問題
tonionagauzzi
0
140
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
430
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
23k
Realtime API 入門
riofujimon
0
110
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.3k
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
14
1.9k
Facilitating Awesome Meetings
lara
49
6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
A Philosophy of Restraint
colly
203
16k
Docker and Python
trallard
40
3.1k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Raft: Consensus for Rubyists
vanstee
136
6.6k
KATA
mclloyd
29
13k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
Bash Introduction
62gerente
608
210k
Writing Fast Ruby
sferik
626
61k
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