$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
port-monolith-to-wasm-for-chrome-extension
Search
Linda_pp
January 27, 2020
Programming
0
450
port-monolith-to-wasm-for-chrome-extension
Presented at Rust LT #8
https://rust.connpass.com/event/160225/
Linda_pp
January 27, 2020
Tweet
Share
More Decks by Linda_pp
See All by Linda_pp
actionlint の Linter 設計
rhysd
6
3.4k
ripgrep をライブラリとして使う
rhysd
0
400
Fuzzing Rust Text Editor
rhysd
1
2.9k
Vim compiled to WebAssembly
rhysd
5
2.1k
about-neovim-0.4.0-floating-window
rhysd
3
2.2k
reply.vim
rhysd
0
1.2k
Vim ported to WebAssembly (VimConf 2018)
rhysd
4
3.3k
go-selfupdate-github で ツールを自己アップデートする
rhysd
5
4.3k
小さく始めて育てるコンパイラ
rhysd
13
4.8k
Other Decks in Programming
See All in Programming
Full stack testing :: basic to basic
up1
1
880
[FlutterKaigi2024] Effective Form 〜Flutterによる複雑なフォーム開発の実践〜
chocoyama
1
4k
プロダクトの品質に コミットする / Commit to Product Quality
pekepek
1
670
romajip: 日本の住所CSVデータを活用した英語住所変換ライブラリを作った話
sangunkang
0
2.4k
Discord Bot with AI -for English learners-
xin9le
1
110
PaaSとSaaSの境目で信頼性と開発速度を両立する 〜TROCCO®︎のこれまでとこれから〜
gtnao
6
7.1k
テストコード文化を0から作り、変化し続けた組織
kazatohiei
2
900
.NET 9アプリをCGIとして レンタルサーバーで動かす
mayuki
1
750
React + Tauriでデスクトップアプリ開発に入門してみた
ynishimura0922
0
200
cmp.Or に感動した
otakakot
3
340
React CompilerとFine Grained Reactivityと宣言的UIのこれから / The next chapter of declarative UI
ssssota
7
3.4k
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
4
570
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
A Modern Web Designer's Workflow
chriscoyier
693
190k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
KATA
mclloyd
29
14k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
The Invisible Side of Design
smashingmag
298
50k
Unsuck your backbone
ammeep
669
57k
How to Ace a Technical Interview
jacobian
276
23k
Transcript
Monolith Λ Wasm ʹҠ২͠ ͯ Chrome ֦ுͭͬͨ͘ at Rust LT
#8 (2020/1/27) @Linda_pp @rhysd
monolith https://github.com/Y2Z/monolith
monolith • ࢦఆͨ͠ URL ͷϖʔδΛ1ͭͷ HTML ϖʔδͱ ͯ͠อଘ͢Δ CLI πʔϧ
• ϨεϙϯγϒͳϖʔδͳͲී௨ͷΣϒϖʔδ ͱͯͦ͠ͷ··ϩʔΧϧʹอଘͰ͖Δ • HTML ϖʔδΛύʔε͠ɼϦιʔεΛऔ͖ͬͯͯ Data URL ͱͯ͠ຒΊࠐΉ͜ͱͰ࣮͞Ε͍ͯΔ
monolith-of-web https://github.com/rhysd/monolith-of-web
monolith-of-web • monolith Λ wasm ʹҠ২͠ɼChrome ֦ுͱ ͯ͠ϒϥβ͔Β͑ΔΑ͏ʹͨ͠ͷ • ϒϥζ͍ͯ͠Δϖʔδͷ
HTML Λͦͷ·· ୯Ұͷ HTML ϖʔδʹͯ͠อଘͰ͖Δ
σϞ
:; NPOPMJUI SIZTE NPOPMJUI NPOPMJUIOQN QBDLBHF NPOPMJUIPGXFC CBDLHSPVOEQBHF GPSL XBTNQBDL
JOTUBOUJBUF
େ·͔ͳ wasm ͷҠ২ͷखॱ • wasm-pack buid ͕௨ΔΑ͏ʹ͢Δɽwasm ະରԠͷϞδϡʔ ϧ͕͋Δ߹#[cfg(target_arch =
"wasm32")] ͰॲཧΛ͚ Δ • wasm-bindgen Λ͍ɼ#[wasm_bindgen] Ͱ JS ଆʹݟͤΔ API Λఆٛ͢Δ #[cfg(not(target_arch = "wasm32"))] use reqwest::blocking::Client; #[wasm_bindgen(js_name = monolithOfUrl)] pub async fn monolith_of_url( url_target: String, options: MonolithOptions, ) -> Result<String, JsValue> { // ... }
network ϦΫΤετ • monolith Ϧιʔεͷ fetch ͷͨΊʹ reqwest ͷϒϩοΩ ϯά
API Λ͍ͬͯΔ • JavaScript ͷ fetch() ͱ async-await Λͬͯॻ͖͑ • js_sys::Promise std::future::Future ͷม؆୯ʹͰ͖Δ use wasm_bindgen_futures::JsFuture; let window = web_sys::window().unwrap(); let resp_value = JsFuture::from( window.fetch_with_request(&request) ).await?; let resp: Response = resp_value.dyn_into().unwrap();
࠶ؼؔͷ async-await Խ • ࠶ؼؔ await ࣌ʹอଘ͓ͯ͘͠ঢ়ଶͷαΠζ͕੩తʹ ܾ·Βͳ͍ͷͰɼasync ؔʹͰ͖ͳ͍ɽ •
monolith Ͱ DOM Λ࠶ؼతʹࠪ͠ͳ͕ΒϦιʔεΛ fetch ͍ͯͨ͠ͷͰɼ͜ͷΛ౿ΜͰ͍ͨ // ίϯύΠϧΤϥʔ async fn recursive() { recursive().await; recursive().await; }
࠶ؼؔͷ async-await Խ • ঢ়ଶʢFutureʣΛ Box ʹೖΕͯಈతʹཧ͢Δ͜ͱͰճ ආͰ͖Δ use std::pin::Pin;
use std::future::Future; fn recursive<'a>() -> Pin<Box<dyn Future<Output = ()> + 'a>> { Box::pin(async move { recursive().await; recursive().await; }) }
·ͱΊ • Rust ͷ CLI πʔϧ monolith Λ wasm ʹҠ
২ͯ͠ Chrome ֦ுʹͯ͠Έͨ • https://github.com/rhysd/monolith-of-web • async-await wasm Ͱ wasm_bindgen_futures Ͱ؆୯ʹ͑Δ @Linda_pp @rhysd presented by