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
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
290
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
ヤプリ新卒SREの オンボーディング
masaki12
0
130
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
610
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.3k
Featured
See All Featured
Designing for Performance
lara
604
68k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
The Pragmatic Product Professional
lauravandoore
31
6.3k
The Cult of Friendly URLs
andyhume
78
6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Designing for humans not robots
tammielis
250
25k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Why Our Code Smells
bkeepers
PRO
334
57k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
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