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.3k
CLI Tool開発のためのRust
2017/03/01 "RustのLT会! Rust入門者の集い #2"で使った資料です。
niboshi
March 01, 2017
Tweet
Share
Other Decks in Programming
See All in Programming
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
190
CSC307 Lecture 03
javiergs
PRO
1
490
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
200
Apache Iceberg V3 and migration to V3
tomtanaka
0
160
24時間止められないシステムを守る-医療ITにおけるランサムウェア対策の実際
koukimiura
1
100
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
290
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
460
「ブロックテーマでは再現できない」は本当か?
inc2734
0
1k
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
360
CSC307 Lecture 10
javiergs
PRO
1
660
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
240
CSC307 Lecture 08
javiergs
PRO
0
670
Featured
See All Featured
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
130
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
100
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
430
Chasing Engaging Ingredients in Design
codingconduct
0
110
Leo the Paperboy
mayatellez
4
1.4k
Visualization
eitanlees
150
17k
Agile that works and the tools we love
rasmusluckow
331
21k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
330
Producing Creativity
orderedlist
PRO
348
40k
Building AI with AI
inesmontani
PRO
1
700
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()࿈ଧ… • ࠓ·Ͱҙࣝͯ͠ͳ͔ͬͨΦʔόϔουΛҙࣝͤ͟ΔΛ ಘͳͯ͘ྑ͍ͷ͔
͓ΘΓ