<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kival M on Medium]]></title>
        <description><![CDATA[Stories by Kival M on Medium]]></description>
        <link>https://medium.com/@kival?source=rss-d81905c5a42b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vwQSETJVQj_mJZclYNmG-A.jpeg</url>
            <title>Stories by Kival M on Medium</title>
            <link>https://medium.com/@kival?source=rss-d81905c5a42b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 09:29:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kival/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Single Page Application in Rust(Yew) — Part 1]]></title>
            <link>https://medium.com/@kival/building-a-single-page-application-in-rust-yew-part-1-42e8ce5e3e87?source=rss-d81905c5a42b------2</link>
            <guid isPermaLink="false">https://medium.com/p/42e8ce5e3e87</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[yew]]></category>
            <category><![CDATA[wasm]]></category>
            <dc:creator><![CDATA[Kival M]]></dc:creator>
            <pubDate>Sat, 23 Apr 2022 17:22:06 GMT</pubDate>
            <atom:updated>2022-04-23T17:22:06.942Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Single Page Application in Rust(Yew) — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IhnEBceQZI-8xZ8MkOHB2g.png" /><figcaption>Ferris</figcaption></figure><p>It is possible to build single-page web applications in rust without writing a single line of JavaScript, thanks to the ability of rust to compile into web assembly.</p><p>There are many popular frameworks to aid in developing WASM applications, such as Seed, Draco, and Yew.</p><p>This post will cover setting up the development environment and boilerplate code for your first Yew application.</p><p>This guide will assume you are fairly familiar with the rust and html programming language and have the tools already set up.</p><h3>Setting up the project</h3><p>For this project, we will be using the stable rust toolchain. We can choose this by opening up a terminal and typing:<strong>`rustup default stable.`</strong></p><p>Now, onto our project. Head over to a terminal and enter a folder where you would like to create your project. I personally have a code directory, so you can create that if you want.</p><pre>mkdir code<br>cd code</pre><p>Now we can create our project called ‘first-yew-program’ with cargo.</p><pre>cargo new first-yew-program</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*F0SnduTgH1QrFvGqFvKKjw.png" /></figure><p>Now open it up in your favourite text editor. I am a big fan of VS Code with the rust-analyzer extension. It really makes programming in rust a breeze.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*3HwFtgylqBCxzyM4IwHkMQ.png" /></figure><p>And our project structure should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H7k5EDX1piBMuOPAFNpPsA.png" /></figure><p>We can cargo run the program to ensure that our project is working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*_IEBnt16kK2JHAnhCv8VOg.png" /></figure><p>All good!</p><p>Now we want to include yew in our project. To do that, we can head over to the yew <a href="https://crates.io/crates/yew">crates.io</a> page and copy down the code. The current version of yew is 0.19.3, so we will use that. Head over to Cargo.toml file and append yew = &quot;0.19.3&quot; under [dependencies].</p><p>It should look like this now:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9e67b02521a1aedbf545ee4f63476bd/href">https://medium.com/media/b9e67b02521a1aedbf545ee4f63476bd/href</a></iframe><h3>Basic hello world program.</h3><p>Now that we have all of that out of the way, we can start with a basic hello world program. Head over to main.rs which is where we will be doing all of our programming.</p><p>Now go ahead and copy this snippet of code into your main.rs file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96b1e5c2762eb090e58536cc3eace1f6/href">https://medium.com/media/96b1e5c2762eb090e58536cc3eace1f6/href</a></iframe><p>Line 1 is our import for the yew library<br>Line 3 is our declaration that this function is a special function that can display content.<br>Line 5 is the content we want to display. Content is placed inside the html macro. <br>Note: Strings need to be surrounded by curly braces “{}”<br>Line 10 is our main function that starts our yew app.</p><h3>Adding index.html</h3><p>For our yew program to run. It needs a valid html file to template off. This file will contain valuable information like the title and meta information. Our yew program will run from the body section of the index.html file. <br>We can create a simple <strong>index.html</strong> like the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69ce7fc08879d7a20881c4bd44c0978d/href">https://medium.com/media/69ce7fc08879d7a20881c4bd44c0978d/href</a></iframe><h3>Running our program</h3><p>Now we have completed the foundation of our yew program, but we still need a way to compile and run it. For this we will be using a tool called “Trunk”.</p><p>We can install it very simply through cargo</p><pre>cargo install --locked trunk</pre><p>Now that it is installed we can run our yew application by running in the console. <br>Note: If you have any issues with this step. i.e trunk not found. Try adding cargo directory to your PATH.</p><pre>trunk serve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*5fV55IG-4lCZ2wF796iwrg.png" /></figure><p>We should see an address listed at the bottom of the output. 0.0.0.0:8080<br>We can head to this address in a browser to view our hello world program in action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*n9DJUqdjeOeP3gfLmTYlyA.png" /><figcaption>our output</figcaption></figure><p>Now you can play around with this by adding valid HTML code within the html! macro in our model() function.</p><h3>Source Files</h3><p>You can view the files used in this project on my Github.<br><a href="https://github.com/KivalM/first-yew-program">https://github.com/KivalM/first-yew-program</a></p><p>If you have any issues don’t be afraid to create an issue on the git page, I will be happy to assist. And stay tuned for part 2 of this series of tutorials on Yew.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42e8ce5e3e87" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>