Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Rust & Emscriptenの話
Search
Yosuke Onoue
November 21, 2015
Technology
260
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rust & Emscriptenの話
Yosuke Onoue
November 21, 2015
More Decks by Yosuke Onoue
See All by Yosuke Onoue
ネットワーク可視化の世界
likr
8
7.2k
Think About Front-end Web Development with Rust
likr
2
600
Yewにおけるoff-the-main-thread
likr
1
870
行政事業レビューデータの可視化 / Visualization of Japan's National Budget with JUDGIT!
likr
1
290
モダンJavaScript再入門 / Re-introduction to Modern JavaScript
likr
24
12k
Web-based Data Visualization with Rust and WebAssembly
likr
4
6.3k
Introduction to Graph Drawing
likr
0
580
20190707Ionic_Meetup.pdf
likr
0
500
About the end of the web
likr
2
590
Other Decks in Technology
See All in Technology
LambdaWebFunctionsを試してみた / exploring-lambda-web-functions
koukihosaka
1
340
AI駆動で「他アプリの音を加工できる」アプリを作った
satomasahiro2005
0
150
しろおびから始める!ログ活用の第一歩
shumei_ito
0
950
スキマバイトという雇用形態は存在しないので、雇用期間1日のアルバイト契約を事業者とワーカーが結ぶ手続きを支えるのがタイミーなんです
akitoshiga
0
200
Optunaの最新リリースv5.0について
pfn
PRO
0
120
Local CI × GitHub Actions
gogutan
2
190
コンテナ運用におけるネットワーク・コンテナコストの削減方法/How to Reduce Network and Container Costs in Container Operations
masakiokuda
1
190
Persisting Massive Data with Rails ~Designing for 60 billion rows, and fighting the bottlenecks~ Railsで挑む大量データ永続化 〜600億件を永続化するための設計とボトルネックとの戦い〜
occhi
0
730
AI導入は済んだ。次は統制を作り替える番だ_AI×開発組織 Summit 2026
techtekt
PRO
0
220
宣言型部分更新は何を解決しどこへ向かうのか
shuta13
1
460
Rust で関数型ドメインモデリング
takonda
0
140
初海外で注意すべきこと12選!!!安全快適なre:invent生活にするために
yuuuuuuu168
1
160
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Leo the Paperboy
mayatellez
10
2.4k
Deep Space Network (abreviated)
tonyrice
0
370
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
540
The browser strikes back
jonoalderson
0
1.8k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
300
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
How to make the Groovebox
asonas
2
2.5k
Transcript
Rust & Emscriptenͷ ͓ͷ͏͑ (@_likr) 2015/11/21 2016ͷAltJSʹ͍ͭͯޠΔձ
ࣗݾհ • ͓ͷ͏͑ ( @_likr ) • ՄࢹԽͷݚڀͱ͔ͬͯΔ • ng-kyotoͱGDG
KobeͰελοϑͬͯΔ • D3.jsɺAngularJSɺReactͱ͔ͬͯΔ
ҙ • ωλൃදͰ͢ • ͙͢ʹࣄͰ͑Δٕज़Ͱ͋Γ·ͤΜ • AngularGoogleςΫϊϩδʔͷ͋Γ·ͤΜ • AltJSͷ͋·Γ͋Γ·ͤΜ
ΦϨͷߟ͑ͨ࠷ڧͷ ࣍ੈϑϩϯτΤϯυ։ൃ ͓ͷ͏͑ (@_likr) 2015/11/21 2016ͷAltJSʹ͍ͭͯޠΔձ
Γ͍ͨ͜ͱ • େنɾߴͳWebϑϩϯτΤϯυΞϓϦͷ։ൃ (ܭࢉɾΞϧΰϦζϜͳͲͷΣΠτେ͖͍)
JavaScriptͷਐา • ClassesɺArrow functionsɺModules • DecoratorsɺAsync/Await • Type Annotations •
…
JavaScriptɺWebϖʔδΛνΧνΧͤ͞ΔͨΊ ͚ͩͷػೳ͔Β͠ɺେن։ൃՄೳͳ ख़ͨ͠ϓϩάϥϛϯάݴޠʹͳΓͭͭ͋Δ
ͰɺJavaScript͕ͭΒ͍໘·ͩ͋ΔΑͶʁ
ྫ͑ɺredux JavaScriptͷΦϒδΣΫτΛpureʹอͭͨΊʹɺ • Array.fromɺObject.assignΛͬͨίϐʔ • immutable.jsͷར༻ JavaScriptͰimmutabilityͷอূ͍͠ state action reducer
next state ෭࡞༻ͷͳ͍ؔ →stateͷมߋېࢭʂ immutability: ΦϒδΣΫτ͕มߋ͞Εͳ͍͜ͱ
όάͷԹচ • มߋ͍͚ͯ͠ͳ͍ͷมߋ • มߋͯ͠ҙຯͳ͍ͷมߋ • ΞΫηε͍͚ͯ͠ͳ͍ͷΞΫηε • ্هΛอূ্ͨ͠Ͱͷtestability
ܧ͗͠ܧ͗͠ͷݴޠ༷Ͱɺ ৽͍͠ύϥμΠϜʹै͢Δͷݶքʁ
େنͰߴͳWebϑϩϯτΤϯυΞϓϦΛ ࣮͍͢͠ݴޠʁ
͍ΖΜͳݴޠ… • CɺC++ɺJavaɺScalaɺGoɺ HaskellɺOCamlɺCoffeeScriptɺ TypeScriptɺElmɺHaxeɺClosure Scriptɺ…ʁ
Rust
Rust • https://www.rust-lang.org/ • Mozilla͕։ൃͨ͠γεςϜϓϩάϥϛϯάݴޠ • 20155݄ʹόʔδϣϯ1.0ϦϦʔε • ݱࡏόʔδϣϯ1.4 •
࠾༻ࣄྫɿ Servo (https://github.com/servo/servo)
Rustͷಛ • ࣮ߦ • ߴͳநԽͱޮతͳ࣮ߦΛཱ྆ • ϝϞϦηʔϑ • ϝϞϦͷྖҬ֎ΞΫηεϝϞϦϦʔΫΛࢭ •
εϨουηʔϑ • ϚϧνεϨουϓϩάϥϛϯάͷϛεΛࢭ
ݸਓతͳϝϦοτ • Garbage Collection͕ͳ͍ • ThreadɺSIMDΛඪ४ϥΠϒϥϦͰαϙʔτ • Web AssemblyͷରԠ͕༗
ࠓɺRustͰWebϑϩϯτΤϯυ։ൃ͕Ͱ͖Δͷ͔ʁ
Emscripten
Emscripten • http://emscripten.org/ • LLVM to JavaScript Compiler • C/C++ϓϩάϥϜΛJavaScriptʹม
• ࠷దԽΛ༗ޮԽ͢Δͱasm.jsΛग़ྗ • কདྷతʹWebAssemblyʹରԠ
rust-webplatform • https://github.com/tcr/rust-webplatform • DOM APIͷബ͍ϥούʔ • ηοτΞοϓεΫϦϓτ͖ • cargo-build
(https://github.com/AerialX/cargo-build) • rust-rt-minimal (https://github.com/AerialX/rust)
Hello World 1 extern crate webplatform; 2 3 fn main()
{ 4 let document = webplatform::init(); 5 6 let p = document.element_create("p").unwrap(); 7 p.html_append("hello world"); 8 9 let body = document.element_query("body").unwrap(); 10 body.append(&p); 11 12 webplatform::spin(); 13 }
զʑ͕ཉ͔ͬͨ͠ͷ͜Εͳͷ͔ʁ
ޮྑ͍։ൃͷͨΊʹϑϨʔϜϫʔΫ͕ඞཁͩʂ
Virtual DOMͬΆ͍ͷΛ࣮ͯ͠ΈΔ
RustͰVirtual DOM • ComponentఆٛͱRendererΛ͢Δ • Pure RustͷComponentͱɺ ϒϥβͱΓͱΓ͢ΔRenderer • Mithril(https://lhorie.github.io/mithril/)Λਅࣅ͢Δ
• ܰྔɺγϯϓϧ
࡞ͬͨ 29 pub fn v(tag: &str, attributes: Vec<Attribute>, children: Vec<Node>)
-> Node { 30 Node::Element(Element { 31 tag: String::from_str(tag), 32 attributes: attributes, 33 children: children 34 }) 35 } ཁૉ໊ɺଐੑɺࢠComponentΛड͚औͬͯComponentΛੜ͢Δؔ ComponentΛड͚औͬͯHTMLͷॻ͖ग़͠Λߦ͏ؔ 9 pub fn mount<'a, T: 'a + Component>( 10 document: Rc<RefCell<Document<'a>>>, 11 root: Rc<RefCell<HtmlNode<'a>>>, 12 component: Rc<RefCell<T>>) { 13 let target = root.borrow(); 14 target.html_set(""); 15 let node = component.borrow().render(); 16 render(document, target.deref(), node, root.clone(), component); 17 }
࠶Hello World 8 struct Main; 9 10 impl Component for
Main { 11 fn render(&self) -> Node { 12 v("div", 13 vec![attribute("class", text_value("hoge"))], 14 vec![ 15 v("p", vec![], vec![ 16 text_node("hello"), 17 ]), 18 v("p", vec![], vec![ 19 text_node("world"), 20 ]) 21 ] 22 ) 23 } 24 } 25 26 fn main() { 27 let main_component = Rc::new(RefCell::new(Main)); 28 let document = Rc::new(RefCell::new(webplatform::init())); 29 let body = Rc::new(RefCell::new(document.borrow().element_query("body").unwrap())); 30 vdom::mount(document.clone(), body.clone(), main_component.clone()); 31 webplatform::spin(); 32 } <div class="hoge"> <p>hello</p> <p>world</p> </div>
Data Binding 10 struct Main { 11 state: Rc<RefCell<HashMap<String, String>>>
12 } 13 14 impl Component for Main { 15 fn render(&self) -> Node { 16 let key = String::from_str("message"); 17 let message = self.state.borrow().get(&key).unwrap().clone(); 18 v("div", 19 vec![attribute("class", text_value("hoge"))], 20 vec![ 21 v("p", vec![], vec![ 22 Node::Text(message.clone()), 23 ]), 24 v("input", vec![ 25 attribute("value", AttributeValue::Text(message.clone())), 26 attribute("change", AttributeValue::EventHandler(Box::new({ 27 let state = self.state.clone(); 28 move |e: &mut Event| { 29 let key = String::from_str("message"); 30 let mut st = state.borrow_mut(); 31 let node = e.target.as_mut().unwrap(); 32 st.insert(key, node.prop_get_str("value")); 33 } 34 }))), 35 ], vec![]) 36 ] 37 ) 38 } 39 } onchangeͷΠϕϯτϋϯυϥͰstateΛߋ৽ stateͷ༰Λදࣔ
• ྑ͔ͬͨ͜ͱɿܕ͕ݫ֨ • mutabilityɺownershipʹΑ͕ͬͯ Ͳ͜Ͱมߋ͞ΕΔͷ͔ϋϯυϦϯά͕༰қ • ѱ͔ͬͨ͜ͱɿܕ͕ݫ֨ • ΠϕϯτϋϯυϥΛॻ͘ͷʹҰۤ࿑
TODO • ࠩߋ৽ • σʔλϑϩʔ • RustϑϨϯυϦʔͳUtility • ੑೳଌఆ •
…
·ͱΊ • ͍Ζ͍Ζະ • Rustૉఢɺͯ҆͘શͳͣ • Virtual DOMΛ࣮͠Α͏ • ޙʹ͜ΜͳWebϑϩϯτΤϯυ։ൃ͕
ݱ࣮ͷͷʹͳ͍ͬͯΔ͔ʁ
ng-kyoto Angular Meetup #3