Let's discuss the benefits of writing fullstack Rust, as well as crossplatform development for Desktop and web targets. What are pros and cons of this approach? I've been using Rust in the browser since early days and noticed a number of interesting points.
Shared code and data structures: one of the key benefits for me personally is that you don't need to document you api with tools like swagger. Define the shared data structures in a module, import it on the client and server sides, and you are good to go. In addition, thanks to serde it's easy to switch between different serialization formats. Want to switch from JSON to MessagePack? Define encode/decode function in the shared module and use them from both client and server. Now changing the format takes a few lines of code.
One language: you can switch between writing client and server without a lot of effort. Of course, WebAssembly adds technical overhead. But I would argue that it's less than using two different languages. Still, there's a need to write platform dependent code at times, and it requires the familiarity with the target platform.
One package manager: when you use a language it's not only about the syntax, but also the ecosystem. And crates.io provides solutions for many common problems already. It saves a lot of time if you have only one package ecosystem to explore. As far as it has the packages you need, of course.
A bit more about WebAssembly: it was created when people wanted to build desktop applications for the browser. And now it's just a nice and convenient benefit when you make a desktop app, but you have an option to build it for the web too.
Binary size: the example application has .wasm file of 4.4Mb when compiled in release mode and optimized with wasm-opt from binaryen.
Font loading: when you use canvas to render your app in the browser, there's a need to load the fonts and it can easily add another 10Mb to the downloading data depeding on the fonts used.
In the end, I'd like to thank all the people who are working on the tools and ecosystem. It's possible only because of your hard work!
What do you think about fullstack and crossplatform development in Rust?
rekireki•2h ago
Shared code and data structures: one of the key benefits for me personally is that you don't need to document you api with tools like swagger. Define the shared data structures in a module, import it on the client and server sides, and you are good to go. In addition, thanks to serde it's easy to switch between different serialization formats. Want to switch from JSON to MessagePack? Define encode/decode function in the shared module and use them from both client and server. Now changing the format takes a few lines of code.
One language: you can switch between writing client and server without a lot of effort. Of course, WebAssembly adds technical overhead. But I would argue that it's less than using two different languages. Still, there's a need to write platform dependent code at times, and it requires the familiarity with the target platform.
One package manager: when you use a language it's not only about the syntax, but also the ecosystem. And crates.io provides solutions for many common problems already. It saves a lot of time if you have only one package ecosystem to explore. As far as it has the packages you need, of course.
A bit more about WebAssembly: it was created when people wanted to build desktop applications for the browser. And now it's just a nice and convenient benefit when you make a desktop app, but you have an option to build it for the web too.
Binary size: the example application has .wasm file of 4.4Mb when compiled in release mode and optimized with wasm-opt from binaryen.
Font loading: when you use canvas to render your app in the browser, there's a need to load the fonts and it can easily add another 10Mb to the downloading data depeding on the fonts used.
In the end, I'd like to thank all the people who are working on the tools and ecosystem. It's possible only because of your hard work!
What do you think about fullstack and crossplatform development in Rust?