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
CLI Tool開発のためのRust
Search
niboshi
March 01, 2017
Programming
1
1.2k
CLI Tool開発のためのRust
2017/03/01 "RustのLT会! Rust入門者の集い #2"で使った資料です。
niboshi
March 01, 2017
Tweet
Share
Other Decks in Programming
See All in Programming
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Contemporary Test Cases
maaretp
0
140
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
270
Macとオーディオ再生 2024/11/02
yusukeito
0
380
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.3k
最新TCAキャッチアップ
0si43
0
200
Jakarta EE meets AI
ivargrimstad
0
720
React への依存を最小にするフロントエンド設計
takonda
12
3.3k
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.2k
cmp.Or に感動した
otakakot
3
230
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Code Review Best Practice
trishagee
64
17k
Fireside Chat
paigeccino
34
3k
Producing Creativity
orderedlist
PRO
341
39k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Teambox: Starting and Learning
jrom
133
8.8k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
How GitHub (no longer) Works
holman
310
140k
BBQ
matthewcrist
85
9.3k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Adopting Sorbet at Scale
ufuk
73
9.1k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Transcript
CLI Tool։ൃͷͨΊͷ Rust ʹ΅͠(@mpppk)
Rustೖऀͷू͍(૾) ͢͝ʔ͍ MFUzϨοτzͬͯ ಡΉΜͩΑ ͳΔ΄Ͳ ʔ
Rustೖऀͷू͍(ݱ࣮)
େมͳͱ͜Ζʹདྷͯ͠·ͬͨ (ݫ͍͠ϚαΧϦ͓ئ͍͠·͢ʂ)
ʹ΅͠(@mpppk)
mpppk/skylarq • yamlͰॻ͍ͨ༰ʹ ैͬͯɺϑΝϛϨεͷ Ξϯέʔτʹࣗಈճ ͯ͠ΫʔϙϯΛ͏ CLI Tool(Node.js)
RustͰCLI Tool࡞Γ͍ͨ
RustΛ࢝ΊΔࡍͷ (ͨͿΜ)ҰൠతͳϞνϕʔγϣϯ • ϝϞϦ҆શ • ϦΞϧλΠϜੑ • ϨΠϠʔ৮ΕΔ • WebAssembly
γϡοͱCLI࡞Γ͍ͨͱ͖ʹ Rustྑ͍ͷͰઆ • ΫϩείϯύΠϧ • όΠφϦ1ͭͰಈ࡞ • ϨΠϠʔ৮ΕΔ • Ϧονͳจ๏(iterator,
pattern match, etc…) • ඞཁेͳϥΠϒϥϦ
ྫ͑ jqΫϩʔϯΛ࡞Δͱ͢Δͱ • ඞཁͳͷ • serializer/deserializer • option parser •
query parser
Serialiser / Deserialiser
serializer/deserializer ͷબࢶ • Serde(˒674) • rustc-serialize(˒166) • ࠓޙSerdeʹஔ͖Θ͍ͬͯ͘Β͍͠
Serde • γϦΞϥΠζ/σγϦΞϥΠζͷͨΊͷFW • ҙͷstructʹରͯ͠derive attributeͰ Serialize/Deserialize Trait͕࣮͞ΕΔ • ࣗલͰTraitΛ࣮͢Δ͜ͱͰ֦ுՄೳ
Serde Example: serde_json
SerdeରԠࡁϑΥʔϚοτ
Option Parser
Option parserͷબࢶ • clap-rs(˒947) • ࡉ੍͔͍ޚ͕Մೳ • getopts(˒49) • Rustެࣜ
• ϛχϚϧͳ༷ • docopt.rs(˒452) • cargo͕࠾༻ • ϔϧϓϝοηʔδ͔ΒࣗಈͰparser͕ੜ͞ΕΔ
clap-rs (Option parser) • Builder PatternͰίϚϯυϥΠϯҾΛఆٛ
clap-rs (Option parser) • --help--version͕উखʹ࣮͞ΕΔ
Query Parser
query parserͷબࢶ • nikomatsakis/lalrpop(˒371) • ಠࣗߏจ • Ұ෦ͷsyntax͕௨Βͳ͍ͳͲɺ·ͩൃలத • kevinmehall/rust-peg(˒342)
• ಠࣗߏจ • Geal/nom(˒1212) • parser combinator • byte୯ҐͰͷॲཧ͕Մೳ • RustͷϚΫϩͱͯ͠ఆ͍ٛͯ͘͠
lalrpop (query parser) • parser generator + α • ୯ͳΔߏจͷߏங͚ͩͰͳ͘
۩ମతͳॲཧ༰ҰॹʹఆٛͰ͖Δ
mpppk/aq • ͱΓ͋͑ͣ.fooͷύʔεΛ Ͱ͖ΔΑ͏ʹ͚ͨͩ͠ • ͍ΖΜͳϑΥʔϚοτʹରԠͰ͖Δͱ ศརͦ͏
·ͱΊ • CLI͋Μ·ؔͳ͔ͬͨ • ཉ͍͠ͱࢥͬͨϥΠϒϥϦ͍͍ͩͨ͋Δײ͡ • Rustͷײ • Pattern matchॆ࣮ͨ͠IteratorͷAdapter/Consumer
͕͋ͬͯॻָ͍͍ͯͯ͠ • ͱʹ͔͘ίϯύΠϧ͕௨Βͳ͍ • ϝιουʹΓग़͚ͨͩ͠ͰΤϥʔ • ͱΓ͋͑ͣclone()࿈ଧ… • ࠓ·Ͱҙࣝͯ͠ͳ͔ͬͨΦʔόϔουΛҙࣝͤ͟ΔΛ ಘͳͯ͘ྑ͍ͷ͔
͓ΘΓ