Slide 1

Slide 1 text

Ciro Nunes 14 Sep 22 Rust Front-end with Yew πŸ¦€πŸ‡¦πŸ‡Ί

Slide 2

Slide 2 text

Agenda ⁉ What is Yew? Why Wasm & Rust? πŸͺ„ Simple tutorial 🀩 My impressions πŸ—Ί Where to go from here

Slide 3

Slide 3 text

What is Yew? Why Wasm & πŸ¦€?

Slide 4

Slide 4 text

What is Yew?

Slide 5

Slide 5 text

Yew Rust / Wasm client web app framework

Slide 6

Slide 6 text

Yew Multi-threaded front-end web apps using WebAssembly πŸŽπŸ’¨

Slide 7

Slide 7 text

Yew Multi-threaded front-end web apps using WebAssembly πŸŽπŸ’¨ β€’ Component-based

Slide 8

Slide 8 text

Yew Multi-threaded front-end web apps using WebAssembly πŸŽπŸ’¨ β€’ Component-based β€’ Great performance

Slide 9

Slide 9 text

Yew Multi-threaded front-end web apps using WebAssembly πŸŽπŸ’¨ β€’ Component-based β€’ Great performance β€’ JavaScript interoperability

Slide 10

Slide 10 text

Why Wasm?

Slide 11

Slide 11 text

WebAssembly Low-level assembly-like language with a compact binary format that runs with near-native performance and provides languages like Rust with a compilation target that can run in modern web browsers.

Slide 12

Slide 12 text

WebAssembly Not a silver bullet for improving performance of web apps πŸ€ͺ

Slide 13

Slide 13 text

WebAssembly Not a silver bullet for improving performance of web apps πŸ€ͺ β€’ DOM APIs from Wasm are still slower than directly from JS

Slide 14

Slide 14 text

WebAssembly Not a silver bullet for improving performance of web apps πŸ€ͺ β€’ DOM APIs from Wasm are still slower than directly from JS β€’ Perfect for heavy computation applications

Slide 15

Slide 15 text

WebAssembly Not a silver bullet for improving performance of web apps πŸ€ͺ β€’ DOM APIs from Wasm are still slower than directly from JS β€’ Perfect for heavy computation applications β€’ Multi-threading via Web Workers

Slide 16

Slide 16 text

Why Rust?

Slide 17

Slide 17 text

Rust Helps developers write safer code with its rich type system and ownership model

Slide 18

Slide 18 text

Simple tutorial

Slide 19

Slide 19 text

Let’s build a To-do app

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

# [ derive(Clone)] struct Todo { text: String, completed: bool, }

Slide 23

Slide 23 text

struct TodoComponent { todos: Vec, new_todo_txt: String, }

Slide 24

Slide 24 text

enum Msg { AddTodo, UpdateNewTodo(String), }

Slide 25

Slide 25 text

impl Component for TodoComponent { type Message = Msg; type Properties = (); fn create(_ctx: &Context) - > Self {} fn update(&mut self,_ctx, msg: Self : : Message) - > bool {} fn view(&self, ctx: &Context) - > Html {} }

Slide 26

Slide 26 text

fn create(_ctx: &Context) - > Self { Self { todos: vec![Todo { text: "Learn Rust".to_string(), completed: true, }], new_todo_txt: "".to_string(), } }

Slide 27

Slide 27 text

fn view(&self, ctx: &Context) - > Html { let link = ctx.link(); let on_cautious_change = link.batch_callback(|e: Event| { let input = e.target_dyn_into: : < HtmlInputElement>(); input.map(|input| Msg : : UpdateNewTodo(input.value())) }); html! {
    { self.todos.iter().map(|todo| html! {
  1. {format!("{}", todo.text)} < / span> < / li> }).collect: : < Html>()} < / ol>
    { "Add" } < / button> < / div> < / div> } }

Slide 28

Slide 28 text

fn update(&mut self, _ctx: &Context, msg: Self : : Message) - > bool { match msg { Msg : : AddTodo = > { let new_todo = Todo { text: self.new_todo_txt.to_string(), completed: false, }; self.new_todo_txt = "".to_string(); self.todos.push(new_todo); true } Msg : : UpdateNewTodo(new_txt) = > { self.new_todo_txt = new_txt; true } } }

Slide 29

Slide 29 text

use yew : : prelude : : *; fn main() { yew : : start_app: : < TodoComponent>(); }

Slide 30

Slide 30 text

My impressions

Slide 31

Slide 31 text

My impressions Yew

Slide 32

Slide 32 text

My impressions Yew β€’ Very similar to React, but it’s Rust

Slide 33

Slide 33 text

My impressions Yew β€’ Very similar to React, but it’s Rust β€’ Easy to setup and learn the basics

Slide 34

Slide 34 text

My impressions Yew β€’ Very similar to React, but it’s Rust β€’ Easy to setup and learn the basics β€’ Good documentation

Slide 35

Slide 35 text

My impressions Yew β€’ Very similar to React, but it’s Rust β€’ Easy to setup and learn the basics β€’ Good documentation β€’ Looks promising

Slide 36

Slide 36 text

Where to go from here

Slide 37

Slide 37 text

Where to go from here Yew

Slide 38

Slide 38 text

Where to go from here Yew β€’ Check out the docs yew.rs

Slide 39

Slide 39 text

Where to go from here Yew β€’ Check out the docs yew.rs β€’ Learn about Properties, Function Components, Hooks, Agents and the Router

Slide 40

Slide 40 text

Where to go from here Yew β€’ Check out the docs yew.rs β€’ Learn about Properties, Function Components, Hooks, Agents and the Router β€’ Checkout stylist for CSS-in-Rust

Slide 41

Slide 41 text

Where to go from here Yew β€’ Check out the docs yew.rs β€’ Learn about Properties, Function Components, Hooks, Agents and the Router β€’ Checkout stylist for CSS-in-Rust β€’ Take advantage of Rust parallelism in Wasm for heavy computations

Slide 42

Slide 42 text

Thanks for listening ✌