I spent six months rewriting everything in Rust

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I'm tired of my software breaking when I don't touch it for a while so I spent the last six months making a big bet and rewriting everything I depend on for my income in rust from the apis I use to the tooling I use to update data to the way I edit videos even the websites themselves are now written in Rust so how do we get here I've been paid to write a fairly wide assortment of languages over the years it all started with actionscript which was the first language I got paid to write before Apple promptly extinguished its existence forever then came JavaScript it didn't turn out to be too much different honestly but it did come at a time when node.js was first making its entrance into the world and node opened up a whole new world for me node empowered me to think about servers and databases it brought me into the world of CLI tools desktop applications and more note in JavaScript gave me the language to talk about package managers and somewhat ironically to think about build tooling the core Point here is that node in the JavaScript ecosystem empowered me at the time to do more than I was doing but we'll come back to that I also had experiences that were significantly less empowering I learned Haskell after JavaScript and got paid to write that for a while Haskell was hard to learn perhaps due to it being one of my earlier languages hard to use and unrewarding to share with others it was the language that taught me no matter how interesting or technically Advanced the tool was it wouldn't be successful without a community around it that cared about and put effort towards things like documentation onboarding user experience and psychological safety Haskell taught me some very interesting ideas but in the end it wasn't a language I could suggest to other people to learn and use then came a job at Docker where I learned golang go was fine and there were parts of it I really liked static and fairly easily buildable binaries as well as how I could suggest the language to anyone and the community would be there to help them learn and use the language it was pretty easy to pick up and get going which is kind of the point of go even if mastering it wasn't as easy but even though I used go for a number of years I was never really happy with it it still felt too easy to end up with some usage that I wasn't using correctly and that I needed to know the magic rules to know why I never really felt confident writing go more like I was constantly defensive and unsure that I had remembered to satisfy all cases this brings us to the language we're all here to talk about rust if it's not clear by now I'm a person who likes learning new languages there's a long trail of languages I've gotten used to writing but never been paid to write or not continued using for very long lisps like e-list or closure erlang Etc so it should be no surprise that I was experimenting with rust and by 2019 I had written enough rust to get through the Advent of code problems that year and it was clear to me that this was a language that I could use for a long time but why what made rust the right choice for me first off I keep two languages fresh and available to use for Contracting at any given time this is almost always JavaScript and one other language there's just no replacement for JavaScript on the web Russ has the amazing and fairly straightforward benefit of having come after a long line of other languages and platforms this affected how it grew both from a technical perspective as well as a social one rust isn't what I'd consider a state-of-the-art language at least in the research sense but it had the benefit of being built decades after many other popular languages and learning from their successes and mistakes on the technical side there's a lot to love some of what attracted me at the time was some in product types probably better known to U.S enums and structs that can carry data and this is something I first experienced in Haskell and in my opinion is a necessity for any new language that I intend to use rust also has a powerful modern package manager in cargo which also means tests are built in no more installing third-party packages just to be able to test my applications this means I tend to write more tests and those tests help me find problems more often rust also has a distinction between safe and unsafe code I personally don't want to be messing with no pointers unless I'm working in a domain that demands low level control like embedded systems so it's important to me that while the language can support low level control it also can be usable as a high level language on the social side there's also a lot to love the website prioritizes a message of empowering people and the community is supportive and inclusive as someone who brings people into the rust ecosystem I continue to take my own own impact on that seriously most critically of all it was a language that replicated the feeling of empowerment that I originally felt in the node.js ecosystem it was a language that expanded the types of software I was capable of building so what is rust capable of rust is well known for being a capable tool for command line applications and has a reputation for being a solid low level tool that can build high performance applications of all kinds from things like kernel drivers to networking to games and embedded systems rust is less well known for being a solid high level tool comparable to JavaScript and I think this comes a lot from the early marketing for rust being constantly compared to C and C plus plus with async await Futures enclosures writing your average web API feels a lot like writing a version of JavaScript that had types built in from the beginning instead of patched on afterwards a few notable projects in the rest ecosystem that show what rust is capable of are clap for building CLI tools and argument parsing Bevy for building games wgpu for programming the GPU which is a crate that is also used to power firefox's implementation of web GPU Tokyo to power async await as an async runtime and axum for web apis and other web framework concerns Embassy for building embedded systems and rayon for parallelism contrasting against Tokyo for async you can avoid regex's for parsing with crates like Nam and other parser combinators integration with cargo allows people to build tools like cargo Lambda which allows you to build rust binaries for serverless applications on AWS Lambda really easily building for wasm applications is made easier by using wasm bungen and there's a plethora of tools that integrate rust with other languages like nap IRS I think in particular this last point the fact that rust can work with other languages rather than versus other languages is really important you can build a rust program that runs inside of a JavaScript context or powers of python context or powers and elixir context and this compatibility of being able to build programs that live inside of other are ecosystems and allow people to use the languages that they're comfortable with while also receiving the safety and performance benefits of rust is really important there's of course too many crates to name here spanning almost every category I've ever considered writing software in and at this point I already write so much software in Rust anyway it will probably not come as a surprise then to anyone familiar with rust that I was able to use it well for building rest apis talking to databases CLI tools audio processing for my recordings and more very successfully the final question for this project was if Russ could handle the last workload that I was still depending on another language for UI on the web luckily for me there's been a lot of progress on that front over the last year so let's take a look at one of the applications I'm rewriting and see what it's like one of the applications I rebuilt over the last six months is the site I used to host and distribute written and video educational content it's called rust Adventure as a side note if you do enjoy my videos please do support the channel by subscribing to rust Adventure it's 30 a month and provides it's a more well-researched structured approach to learning rust up until this point rust Adventure was written using serverless functions and JavaScript there was some Rust powering a custom build system for the website as well as rust powering some of the apis but there was also a lot of JavaScript in my mind this site contains everything you need to build a software as a service product features like user accounts and integration with Cognito or AWS integration with services for payments like stripe and API that has to serve multiple clients multiple web uis both customer facing as well as admin facing content management tools and more the new architecture needed a few changes though first I changed the database the old site used dynamogb which it served me well but I was encountering more priority for being able to change schema migrate data and generally build admin tools to interact with the database itself so I migrated to Planet scale's hosted version of a test flavored MySQL for the added flexibility it gave me it also gives me a git Branch type workflow as well as some safety guards now next I had to decide what to do with the API the old site used AWS appsync a graphql implementation from AWS with rust-based resolvers appsync integrates really well with Cognito which I'm using for user accounts but I didn't feel very happy with needing to use amplify to query it which seems to be aws's General suggestion for anything these days I swapped away from the graphql approach to use axum and Tokyo to power the MySQL based rest API Aksum has the advantage of being tightly integrated into the Tokyo and Tower ecosystem as well as having a plethora of examples which is common in the rust ecosystem I do love being able to go into any random rust crate GitHub repo and find a folder of examples showing me how to use that crate axum doesn't rely heavily on Macros which I find produces better error messages and uses an extractor API that reminds me of working with Betty's ECS queries you might recognize this as dependency injection with the API framework chosen I needed to figure out where to deploy it I have background with using Docker from having worked at Docker and finding a platform that uses Docker files these days is like trying to find oxygen on Earth fly.io has the advantage of using wire guard under the hood for internal networking and is powered by firecracker a micro VM that also Powers AWS Lambda AWS fargate and is you guessed it also written in Rust axum and rust for web apis is fairly uncontroversial in my mind rust is graded API writing routes looks a lot like writing routes in any other language with the minor exception of the way types are used often with destructuring Saturday is absolutely fantastic for serializing or deserializing data and SQL X or actually a number of other crates as well are available to query a database all of my queries are checked to compile time against the database schema and if you prefer something that is a little bit more orm based there are options for you as well so getting back to the big question for me again can rust work for web UI and how do you write web UI in Rust anyway the answer is an emerging technology called wasm or webassembly it sounds fancy but what it really means is the ability to compile non on JavaScript languages to a format that works on the web in your browser there are a number of possible approaches to building UI in the rust ecosystem and that number is growing all the time a number of those additionally make use of the Dom using this wasam approach I want to be clear that there are other native toolkits in Rust that build UI and deploy it on the web using something like wgpu and rendering to a canvas but I don't consider these viable approaches for the mass Market of websites that are out there when I think about production websites I think about something that makes use of the Dom and takes advantage of things like accessibility that are already built in as well as things like text layout the list at the time I was making this decision looked something like Deoxys Sycamore U and leptos U and dioxis are more react like while Sycamore and leptos are more solid-like using signals I chose to go with leptos which is a newer tool although the others are good too and I look forward to seeing them develop further this project started before leptos had its first official release and completed after leptos hit v0.4 so I've experienced with the upgrade cycle in a fast-moving new framework looks like in Rust lepto supports server-side rendering and rehydration on the client but also tries to change as little as possible issuing a virtual Dom in favor of reactive signals it also features server functions and some nice quality of life improvements like the ability to integrate signals server functions and forms with action forms these forms are then supposed to be progressively enhanced which means that I don't have to rely on JavaScript for my site to work if I don't want to all in all it works I built out the actual rust Adventure site and an admin UI for Content management using leptos I used axum as the server framework for both of the uis as well as the third API service and the experience is as good as any JavaScript based site that I could have built in my opinion which is all I'm really asking I want something that's a reasonable alternative to JavaScript that's maintainable and that I can come back to without it being unbuildable because I didn't touch it this month it's not all sunshine and rainbows though while is capable of shipping a wasm UI on the web there are some drawbacks to a typical production when using rust for web UI you lose access to a lot of the JavaScript ecosystem pre-built tools especially tools that are integrated with Frameworks already like framer motion are lost but you also gain the ability to use industry strength crates like wgpu and you can wozmbine gen to any vanilla JavaScript libraries that are out there some of these third-party dependencies are replaceable or even usable as is for example I'm using a mux web component for video playback but you're definitely committing to building more of it yourself now this could also be seen as an opportunity if you're looking to become more of an open source maintainer but it is additional work and you do have to expect it this problem likely solves itself over time as more and more people start to write rust and wasm websites for example react has been around for more than 10 years at this point it would kind of be unfair to expect a framework that's only been around for a year to match up one to one with a framework that's been around 10 times longer which which leads to another take a lot of the rust web UI space is very new you may not be able to find people who have five years of rust web UI knowledge that said CSS toolkits all still work whether you're an old hat that uses bootstrap or one of the newer Kids on the Block like Tailwind there are features that we've become accustomed to in JavaScript build tools like code splitting that we don't get with wasm and this is kind of where we start running up into the wasm spec itself and how it's going to develop in the future so in certain cases it may be tougher to learn how to get multiple was and built packages to work together for example something like ride animations with a wasam-based leptos application and third-party services don't always have rust sdks stripe for example has an official JavaScript SDK but doesn't have an official rust SDK it still all works fine I'm able to set up Checkout sessions handle web Hooks and more but someone had to put the rust SDK together and the same goes for other services for example when trying to use Cognito there's the AWS rust SDK from AWS Labs but it's labeled as developer preview even though it work works just fine for my use cases and I haven't had any issues as for download sizes and performance I haven't noticed it being any different than other JavaScript applications there's definitely a new brand of wasm optimization that you'll have to learn if you go down this path and paying attention to the size of dependencies isn't necessarily the domain of every crate that you'll want to use all in all rust does really well at the things that rust is rumored to do well at servers CLI tools audio processing Etc and I've found it to be a suitable replacement for even higher level languages like JavaScript the most exciting part for me in all of this is that wasn't based websites are a real possibility these days and while shipping them is still in the early days you can still build real production websites with rust today I skipped over a lot in this video there's a lot of the project that I didn't talk about things like audio processing XML generation for Da Vinci a bunch of the CLI tools that I use because I feel like a lot of those domains are things that people think rust is already good at if you want to know more about stuff like that leave a comment and I'm happy to make more videos about any aspect of this have a great rest of your day and check out the rest Adventure website the production version now runs on leptos and is entirely written in Rust have a great rest of your day and I'll see you in the next one
Info
Channel: chris biscardi
Views: 414,125
Rating: undefined out of 5
Keywords: rustlang, rust, programming, leptos, wasm
Id: vL2nB1VwX1M
Channel Id: undefined
Length: 15min 11sec (911 seconds)
Published: Tue Aug 15 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.