DEV Community

Cover image for Exploring Rust for Web Development.

Exploring Rust for Web Development.

Mukhil Padmanabhan on December 19, 2024

As web applications become more and more complex, developers are constantly in the lookout for tools and technologies that can deliver higher perfo...
Collapse
 
sentinelaeux profile image
sentinelae

This is an absolutely awful idea for many reasons. WebAssembly is just a JS blackbox. Wasm is potentially faster due to it being able to abstract operations to its inner context, but unless you're going to reimplement everything related to render better than it currently is, which would defeat the whole purpose, since in this case things are way worse than doing things like a human being.
It all comes down to complexity versus features. You have way more features, way more mature, way more efficient, with way less complexity just by avoiding doing something like rust for webdev.
As much as people try to avoid HTML, CSS and JS, in the end that's all that matters in the web, no matter how bad are the choices behind. It's always simpler and better to just use HTML, CSS and JS.

Collapse
 
iannismccluskey profile image
iannismccluskey

I've been trying to start using WebAssembly with Rust for years. I've followed several tutorials, only a few of which got me started – and those ended up breaking a few updates later. Your second step explanations, in only a few lines, got me started. Thank you so much. You made my New Year's Eve. :-)

Collapse
 
valeriavg profile image
Valeria

While I fully support the suggestion to use Rust for parts that require heavy computation or memory management, developing UI in WASM would result in huge packages, clunky developer experience and zero benefits to performance because the heavyweight render process is already hyper optimised by the browsers and the scaffold to connect UI to wasm package would be much bigger than writing UI itself.

Collapse
 
kinsondigital profile image
KinsonDigital • Edited

I could take any language and compile it to wasm code and it would perform the same for the most part because they're both wasm code.

What I mean is that it's not actual rust that is running in the browser, it is the wasm that runs in the browser.

This is how I thought it worked but I could be wrong.

Collapse
 
dyfet profile image
David Sugar • Edited

Some languages may be very heavy in minimum runtime support they require. The advantage rust has is that rust wasm has is no explicit or large "runtime" library to carry along and bundle with it (compared to go, for example), so you can make very small wasm rust binaries to start with. But you will still need some wasm compiled rust ui framework to bundle into it to do anything useful. I did explore Qt wasm for awhile, but that requires a static wasm Qt build, which, while supported, along with C++ on wasm, using emscript to compile it, produces rather huge wasm files to deploy. Is yew a tight rust ui framework for web/wasm? If so, yes, rust could become a more realistic player. I am guessing yew is to rust what blazer tries to do for C#.

Collapse
 
mark_ellis_fc53cc851d3822 profile image
Mark Ellis

Yea if you wanted to run Python in wasm you’d have to compile the entire interpreter into to wasm.
And yea well, Python is garbage at the best of times.

Collapse
 
mark_ellis_fc53cc851d3822 profile image
Mark Ellis

I probably would bother using wasm to render html, but for computational intensive tasks running on the front end absolutely. I essentially just use Java script to render the front end and glue everything together, that’s what script languages are for, that’s what they’re good at, heavy computations not so much.
Backend usually because the environment is known I’d use FFI to call rust from whatever script not WASM s it will run faster and they’re less overhead, WASM does isolate native code and can be more secure though, so if I were calling c libraries that I didn’t write, either from Java script or rust then I’d use web assembly on the server.

Collapse
 
robertomaurizzi profile image
Roberto Maurizzi

You should definitely take a look at the Leptos project

Collapse
 
tharcissentirandekura profile image
Ntirandekura Tharcisse

If you have experience with React, you may try yew which is more similar to React and it is macro based component similar to React again but I was recently working on my project and I ended up shifting to struct based comonent because I found more support.

Give it a shot, u may like it.

Collapse
 
ddebajyati profile image
Debajyati Dey

Is there currently any great library/framework for building website frontend in rust?

Collapse
 
robertomaurizzi profile image
Roberto Maurizzi

Leptos looks very promising

Collapse
 
smartstak profile image
smartstak

Rocket framework is better for web development

Collapse
 
sanampakuwal profile image
Sanam

tldr. rust is not for webdev

Collapse
 
lurodriguez profile image
L Rodríguez

I will try this, not sure if even if a website can be done with Rust, is better than the current options ( javascript, node, php, etc )