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
CSC509 Lecture 08
javiergs
PRO
0
100
The future of development – Are our jobs getting harder or easier?
hollycummins
1
250
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
15
3.9k
組織に自動テストを書く文化を根付かせる戦略(2024秋版) / Building Automated Test Culture 2024 Autumn Edition
twada
PRO
10
4.5k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
4
22k
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
340
2万ページのSSG運用における工夫と注意点 / Vue Fes Japan 2024
chinen
3
1.3k
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
460
OpenTelemetryでRailsのパフォーマンス分析を始めてみよう(KoR2024)
ymtdzzz
4
1.4k
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
230
Mastering Dependencies in Kotlin Multiplatform
tomifabian
0
100
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
120
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.1k
Six Lessons from altMBA
skipperchong
26
3.4k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
225
22k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.8k
A Modern Web Designer's Workflow
chriscoyier
692
190k
Automating Front-end Workflow
addyosmani
1365
200k
A better future with KSS
kneath
238
17k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
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()࿈ଧ… • ࠓ·Ͱҙࣝͯ͠ͳ͔ͬͨΦʔόϔουΛҙࣝͤ͟ΔΛ ಘͳͯ͘ྑ͍ͷ͔
͓ΘΓ