Looking for more podcasts? Tune in to the Salesforce Developer podcast to hear short and insightful stories for developers, from developers.
34. An Introduction to Rust
Hosted by Chris Castle, with guests Carol Nichols and Jake Goulding.
Rust is a type-safe, concurrent, and memory efficient language from Mozilla. Developers from various backgrounds are turning towards it more as a means of quickly writing performant and functional code for browsers, cryptocurrencies, operating systems, CLIs, and--oh yeah, embedded devices. Carol Nichols and Jake Goulding are Rust instructors and enthusiasts, and they join Chris Castle to talk about Rust's underlying strengths as an ideal blend of simpler languages, like Ruby, with more memory conscious ones, like C. We're also going to give a 40% discount code for Carol and Jake's new video series on Rust, forthcoming from Manning!
You couldn't find a more perfect pair of guests to talk about Rust than Carol Nichols and Jake Goulding. Carol and Jake write books that teach Rust, maintain websites that allow users to run Rust samples, record videos about Rust, and also manage the Rust Belt Rust conference, where Rust developers congregate in the Rust Belt region of America. Carol has a background in Ruby, and always sought to eke out more performance and less memory consumption. Jake has a background in C, but recognizes that it places a heavy burden on a programmer to be mindful of memory leaks and segmentation faults.
Rust is a fantastic programming language from Mozilla. It has a much simpler and intuitive syntax than C, the compiler is optimized to ensure that you are writing memory-safe code, and as a result, it produces executables that run much more quickly (and require less resource consumption) than a dynamic language like Ruby. Carol and Jake delve into how the Rust compiler does this, primarily by aggressively freeing memory and forbidding developers from interactions with dereferenced objects. To newcomers, Rust seems like a forboding language, but Carol and Jake believe that Rust's emphasis on terrific documentation and error messages help guide newbies and veterans alike into writing safer and faster code.
Several large companies see the benefits of Rust and are writing it in production, such as Mozilla, Google, Facebook, and Amazon. Heroku even has an unofficial buildpack for serving Rust applications, and Carol notes that in one of her projects she's paying more for log storage than for dyno consumption, due to how efficiently Rust uses memory.
Rust has an ecosystem-first approach to language design (rather than placing everything into the standard library), which has fostered a largely collaborative open source community. Carol and Jake advise, however, that the language is still evolving, and they don't recommend rewriting all your functional business logic into Rust just yet.
The two conclude by providing many resources on getting started with Rust in the form of books, videos, and coding challenges.
Links from this episode
- Many resources for learning Rust were mentioned in this episode:
- For books, you can get started by reading The Rust Programming Language Book or Programming Rust
- For hands-on coding examples, the Rust Playground allows you to run snippets of Rust code; Rust by Example shows common programming problems solved through Rust implementations; the Rust Cookbook offers slightly longer code samples; and both Rustlings and Excercism.io have interactive tutorials
- Rust in Motion is a video series Carol and Jake are producing to introduce developers to Rust
- The Rust Belt Rust conference is where Rust developers and enthusiasts from around the world will gather to discuss production Rust usage, best practices, and what’s next for Rust.
- crates.io is where Rust packages reside
- Rust is in production at Mozilla, Amazon, and Google
Chris: But personally I found Rust interesting because it has made low-level programming more accessible to me. I never learned C or C++ when I learned to program 20 years ago. Started in Java and went to Ruby and Node and Python and Rust has kind of shown me that I can write lower-level code. But still kind of have this like human friendly developer experience or user experience. For sure Rust has a steeper learning curve than Ruby or Node or Python but its tooling, its documentation, its community and learning resources out there have made learning it a delightful experience. And that brings me to today's guests. Joining me are Carol Nichols and Jake Golding who've contributed much to the Rust Community. Thanks for joining me, Carol and Jake, welcome. Can you... let's start with Carol. Can you give us a little intro about yourself?
Chris: Yeah, same.
Carol: And around that time Steve Klabnik who was and is still a luminary in the Ruby world. He just kept talking about this brand new language called Rust and how awesome it was. And he actually wrote a book called Rust for Rubyists and I was like, "oh cool, I can do this." And I started checking out and it was a way to write faster low resource usage code without the segfaults and the memory problems and a use-after-free and all the problems that come with C. And I was like, "oh, this is just what I need." And I started sending Steve a lot of pull requests for his book and that actually, eventually led into me co-authoring the Rust programming language book with Steve.
Chris: Which is kind of like the canonical Rust learning resources. Is that correct?
Carol: Yeah. We're trying to be... Yeah, it comes with every Rust installation. The book is on your computer installed with Rust. You can also buy a dead tree Version from NoStarch Press. It's not completely comprehensive because Rust is a really big language, but it's aiming to get you productive in Rust and give you what you need to be writing most Rust code.
Chris: So what about you Jake? What is your background and kind of entrance into the Rust world?
Jake: So I kind of came at it from the other direction from Carol. My first big job was a lot and a lot of C code and little bit of a Java, a little bit of Ruby as well. And when I was introduced to Ruby, I was amazed. I was like, "this language is so nice to write compared to C." But I always had that thing in the back of my head where, "oh, but what am I giving up by switching to Ruby?" And I was introduced to Rust through Carol and I kind of just took to it immediately. I was like, "this is great. This is a wonderful high level language that allows you to express ideas concisely." But you still get a lot of performance.
Jake: You have that ability of writing that hardcore C programmer code, but you don't have to give up the things that you normally have to give up when you choose to write C or C++ code. So that really just kind of rang true to me. And because of my background, I see a lot of similarities of kind of a fusion of C and Ruby and obviously there's a lot of other influences in Rust. But to me those two things are kind of like a beautiful marriage and Rust is kind of their offspring there.
Chris: Yeah. That's cool. So, and Carol mentioned she and Steve are kind of the co-authors of the Rust Book. But you also have some kind of pretty major contributions to the Rust Community. What are some of those?
Jake: Yeah, so whatever it is about my brain, I really enjoy answering questions. And so when we started with Rust, it was about Rust 0.13, I think. And at that point in time there was not a lot of content for it on Stack Overflow. And I kind of saw my chance and I said, "I can get in at the ground floor, I can learn a bunch of things by answering questions and I might be slightly addicted to answering questions."
Carol: Definitely addicted.
Jake: It has-
Chris: I saw your little pink Kirby character at the top of the list.
Jake: Yeah. Some of the number one answers on, stack overflow for all things Rust related and it's really been great for me because I've learned a lot, but hopefully I've also helped a lot of other people learn things. And through that, one of the tools that I end up using the most there is taking people's code and testing it. And so I would copy and paste a lot of that into the Rust playground at the time. And over time I kind of how Carol started contributing pull requests to the book. I started saying, "oh, well this part of the Playground needs to be better and this part needs to be better." And I actually ended up re-implementing it and then now I'm the maintainer of the Rust Playground largely because I wanted it as a tool to be able to answer a stack questions more efficiently.
Carol: But yeah, so back up a little bit. The playground is play.rust-lang.org and it's a website where you can just type in some Rust code and then send it off to a server that runs it and then spits the output back in C, you don't have to have Rust installed to be able to try Rust. Anything can like sharing links to programs and things like that.
Jake: Yeah. The goal of it is to make it so that people who are interested in Rust can very easily see what Rust is. Kind of see how the compiler interacts with you and be able to try some things out. It's obviously a great resource for people trying to report bugs or just communicate ideas. But in my mind, one of its biggest goals is to make Rust really accessible to people who want to try it and don't want to spend the 10 minutes to install it or whatever it takes.
Chris: So that was great. Interesting stuff that you used to work on in the Rust world. What is kind of the current big Rust project that you're working on in Rust land?
Jake: So we've got two things that we've been working on currently. One is the Rust Belt Rust conference. This will be our fourth year. It's going to be in Dayton, Ohio on October 18th and 19th. Tickets are on sale now. So we live in the Rust belt in Pittsburgh and we like showing off that there is technology stuff going on in the Rust belt. We're no Silicon Valley or New York City or anything like that. But there are a number of us here and there are benefits to being in the Rust belt. So we've had a conference in Pittsburgh, Columbus, Ann Arbor, and this year is Dayton. So we'd love to have any of your listeners join us for any levels of Rust knowledge. Jake is actually giving an Intro-to-Rust workshop on the first day.
Jake: Yeah, we've done a few conferences over the years and that's always been a strong component of them as an attempt to make them very accessible to first time conference goers as well as people who don't even necessarily know the language.
Chris: I think you had one more thing that you guys are working on right now, right? A pretty kind of a big project that you've been working on for Rust and Rust education.
Carol: Yeah. So the second thing we've been working on is the Rust in Motion video series for Manning. It's a video learning course at that... we're aiming to get you up to speed on the parts that make Rust the most different from most other programming languages.
Jake: Cool and we'll have some... Hopefully we'll figure out how to share some discount codes for that Rust in Motion course so people can, listeners can check it out and see what it's all about.
Carol: Yeah. So the topics we cover in the course that we think make Rust the most different. We do a unit on kind of syntax and basic things. Things like variables are immutable by default in Rust and the way you call function then have structs. And the second unit is on ownership and borrowing, which is a huge difference with Rust, that very few languages make an explicit first-class idea. And what this is, is that in Rust, there is one owner of every piece of data and when that owner goes out of scope, then the data gets automatically cleaned up. So this is the part of Rust that lets you not have to have a garbage collector running while your code is running and cleaning up after you. And also not have to manually think about where you should call free like you have to in C, which everyone gets wrong and leads to problems like segfalse and use-after-frees and things like that. Borrowing is how you can... the owner can let other parts of code use that data without taking over the responsibility of cleaning it up.
Jake: Most languages don't have that. There are some that do C and C++ have concepts of ownership and borrowing. And then the thing that Rust adds on top of that, that is basically unique to Rust. There's a few research languages is this concept of lifetimes where the compiler checks and makes sure that the way that you're using this borrowed data is always valid. You're never going to get into a case of memory and safety.
Carol: Where you've borrowed something and then it's been cleaned up. Like the compiler, makes sure that you aren't doing that. So all borrowers must be shorter than the lifetime of the actual data you're borrowing.
Chris: So I'm most of the way through the Rust book, I'm actually on, is it lifetime annotations? Is that the correct name?
Carol: Yeah. Chapter 10?
Chris: Yeah, that sounds about right. I'm at the point where I feel like my brain is full or needs like more exercises or things like that. So I'm kind of excited to checkout Rust in Motion and maybe a few other things to kind of like layer on top my work through the Rust book so far.
Carol: One of the goals with Rust in Motion was to cover this different stuff because we've watched a lot of people who are good at picking out new programming languages. I used to just being able to take a program, pick up the docs and kind of start typing and get into rewriting their favorite problem and be off and running. With Rust, they try and do that same thing and they hit this brick wall and they kind of freak out. Because you really have to stop and think and understand what the borrow checker is doing and what it's protecting you from and what it's telling you, with the error message is. There's a lot of work put into the error messages. And so I think sometimes people don't read the error messages because they're used to error messages not being helpful. But in Rust they're actually really great.
Chris: Right. I think that even those super helpful messages, like even if you don't know or if you don't know the terms in that error message, you're still going to struggle a little bit if you don't know what lifetime mean or ownership means, yeah.
Jake: And Carol used the phrase and it's a common one among the community of fighting borrow checker. I understand it and I'm always a little disappointed by that choice of words because like the truth is, it is the compiler is attempting to help you. It's trying to say, "hey, this thing that you are attempting to do could introduce security vulnerabilities to your code. Hey, this thing you're trying to do might crash in production." And you don't want to do that. And it really is like you're having a nice well-reasoned discussion with the compiler.
Carol: With your pair, your pair programmer.
Carol: And it just... they're always right.
Jake: They are right 99% of the time, but the vast majority of the time that right.
Carol: Which can get a little annoying but, they're really trying to help.
Chris: Yeah. Jake you mentioned the Rust Community and there is a fun word or name. That's used to the describe the Rust community. Do you know... do either of you know if there's like a story behind that or so. What is the word first of all and is there a story behind where the name came from?
Carol: The word is the Rustacean and it's kind of like Crustacean without the C. Our fun mascot is Ferris The Crab who is a Rustacean. I'm not really sure of the origins of it. I think we were just looking for fun name and someone suggested it and then someone drew a cute crab and there we are.
Chris: So speaking of the community and kind of other users, what are some examples of kind of interesting uses of Rust or like Rust in production in maybe big deployments or maybe like innovative or unique or interesting ways?
Jake: So the most obvious example of Rust in production is through Mozilla. It's in the Firefox browser-
Carol: And it's the most obvious because Mozilla is a huge sponsor of Rust. Rust came out of Mozilla Research, yeah.
Jake: And if you remember, was it a year ago? Two years ago when Firefox released Firefox Quantum. And that was the first public release that had Rust as part of the browser that everyone was running at that point in time. And they integrated Rust into the, it's called Stylo, it's the part that parses the stylesheets and deals with styles inside the browser. And they were able to be very free about using references and especially using references and Multi-threaded context. And because of that they were able to get pretty sizable speedups in that portion of Firefox. Now Firefox still has quite a lot of C and C++ codes. So it's not by any means all Rust, but the pieces that they have been able to port to Rust have gotten really sizeable and noticeable gains.
Chris: As you have spent many years as a software developer. Speed is great and like delivering that thing the first time is great, but then maintainability is always a concern, a question and can be a big problem if it's not kind of planned or thought about. What is or how do people talk about kind of the maintainability story with Rust.
Jake: I compare it to C++: it's way better. A big part of that I think is Cargo, which is the build management and package manager of Rust. Which lets you add dependencies really easily, way more easily than in C++. So that lets you break your program into lots of little components which can be easier to maintain than one big monolith. And I think the compiler being a constant kind of pair to everyone who works on the code base. I've heard this anecdote from a lot of companies is that more junior developers are, you can trust them to write Rust because the compiler is always checking that, you don't have to review their code quite and frankly with more senior developers too. You don't have to review the code quite so carefully. You can review it for like logic problems, which is still very possible in Rust. But as far as like the memory things and security vulnerabilities and, and segfaults and crashes, that sort of thing. So if it compiles, then you know the compiler instruct all of those things. So it makes it a lot easier to bring more people in and more people over time because the compiler is that constant and it really helps out.
Jake: And add on what Carol was saying about crates, Rust definitely is on that side of let's push a lot of stuff into the ecosystem. And there are some people that are not big fans of this concept. My goto example for this that always kind of surprises people is, Rust, The Standard Library, does not have any mechanisms for generating random numbers. Random numbers is actually offloaded to... I'll say third-party crate. A crate that's maintained by people that are close to the core ecosystem of Rust. But still it's just a crate that is distributed on, Crates IO.
Jake: And there's been a lot of work recently in futures for example, with Rust and all of that work has mostly been in the third-party ecosystem. So there's a lot of... do lots of little things. some of the work from Firefox, like there's a URL crates and I'm pretty sure that that came out of the Firefox work because they're like, you know what, "everybody needs URLs and we are really good at URLs because we do web browsers." So they're like, "Let's make that public." And part of that community there is trying to share and trying to have good quality. And that's helped I think with maintenance as well, just because people are cognizant. This is something that we do. We try to make good quality crates that people can use
Chris: Yeah. So that's cool. Actually I want to talk more about, crates.io. But before that I want to hear some more examples of other companies or other kind of interesting uses of Rust. Because I think we... like me in the intro in the beginning and you and I have chatted about CLIs and like embedded devices and all these other different uses for Rust. And I'm curious to hear about some other examples of how those things are being built or who is building those things.
Carol: Yeah. So a lot of the big end tech companies are using Rust in some products. Amazon recently announced their Firecracker MicroVM, which is written in Rust. Google is using Rust for their Fuchsia Operating System, which they're still kind of secretive about what they're doing with it, but it's open source so you can like go see it.
Carol: Yeah. So you can see that it's written in Rust, but we're still not sure what they're doing with it. Facebook is using Rust for a number of projects. They've written a Mercurial server in Rust that can handle their humongous monorepos. They recently announced Libra, their blockchain cryptocurrency is written in Rust. And actually a fun trivia fact. There was recently a congressional hearing where a representative asked an executive from Facebook about why they were using the nightly Rust compiler and what features they needed the nightly compiler for and which is... this is like a very technical detail. And so this came up in congressional texts because they are related to using Rust on Libra, which is aiming to be like a global currency...
Jake: Rust has proven to be a pretty strong case for blockchain in general. There's quite a few projects that are fairly large and fairly mature with regards to blockchain technology. So I think that's a very interesting thing about Rust.
Jake: To my knowledge, it is. Yeah.
Jake: The most real one that I'm aware of and I don't know exactly where they are in the process is the Ember Framework has a t its core, it's called the Glimmer Engine I believe. And it's kind of a diffing algorithm and that that is a piece of that library that is 100% like needs to be performant. It's at the core, it doesn't touch like any DOM really. It's all pure data structury. I know that there was a lot of efforts to get that in Rust and then compile the WebAssembly. I don't know exactly how far they are on that. Obviously with a library like that you're going to have the issue of WebAssembly is a newer technology. And so if you start making that decision, then you have to have some amount of fallback capability for all the people who may not have a WebAssembly-enabled browser for whatever reason.
Jake: That's not... that's different from the Wat talk, right?
Jake: One other thing is that even though it's called WebAssembly, the actual virtual machine, there is a cross platform and conceptually can be used for lots of different things. So I've actually also heard of, there's a Linux kernel I believe a module that allows you to write WebAssembly that then gets run inside of the kernel. I think some of the blockchain technologies as well actually use WebAssembly as kind of their base layer for when you're writing blockchain based applications, they actually get compiled down to WebAssembly. So it's not necessarily WebAssembly is not only the browser, it's obviously has Web in the name, but it is an assembly language and can use in lots of different contexts.
Chris: Is it the new JVM?
Jake: I heard something like that because the idea is you've got a set of assembly, mnemonics that fit and there are interpreters that you can run it.
Carol: This time. This time we'll really make something across platform.
Chris: Well, let's jump back to Rust and the Cargo utility and Crates and specifically like crates.io, which is a project that you're one of the maintainers of Carol is that right?
Carol: Yeah. So Crates IO is kind of like the NPMJS or the Rubygems of the Rust world. It's the package registry website for open source packages. The back-end is written in Rust, the front end is Ember and it runs on Heroku.
Chris: Nice. That's cool. So many people probably don't know that you can run Rust on Heroku. Rust is, I guess it's not one of Heroku's officially supported languages.
Carol: No, it's not. We have to use an unofficial buildpack, so maybe Heroku can get on that since so many other cool people are using it.
Chris: Maybe you can join us and join Heroku and help the dedicated language engineer that makes deploying rust on Heroku a smooth process.
Carol: It's pretty smooth even with the unofficial buildpack because the buildpack like installs, Rust gets the right version, then calls Cargo, which downloads all your packages. Actually this part is really meta, because when we build a new version of Crates IO, it downloads the packages from crates IO and then builds them and then into a single executable or actually we have multiple executable, but the main server is one executable and then we have a bunch of utilities. And then you just kind of run that executable and then your servers running.
Chris: Is that using any popular Rust web framework? And if so, like what is... well I guess in general, what are some of the advantages of using Rust for an application like this versus using say Python or Node or Ruby or Go?
Carol: Because Rust is so young, there isn't like a "Rails for Rust" yet. There isn't like one good web framework yet. There's lots of like pieces of web framework being worked on and different ideas being experimented with. Crates IO was probably one of the first Web applications written in Rust. So it doesn't... it uses this framework that I don't think anyone else uses and no one else should use. Because it was pretty much written for Crates IO and it's not even, I wouldn't even call it a framework. It's like barely a small layer over the network code stuff. So-
Chris: But there are a bunch of different web frameworks that are kind of yeah at different stages of maturity and different levels of use.
Jake: One of the most popular one is called Rocket. It has a pretty amazing developer experience when you're using it. Its biggest downside right now is because the maintainer really wants to help such a wonderful developer experience that they require usage of Rust nightly builds because there are features that they want to use it or not yet stabilized. There's a couple other big ones. So the Rust playground uses Iron Framework. There's another one if you've heard of that TechEmpower Benchmarks, Rust tends to place pretty highly in those. And one of the ones that does really well there is called the Actix Web which is an actor based framework built on top of another, like a library called Actix with the recent stabilization and continuing stabilization of futures and async/await, I think there's going to be a big renaissance in web frameworks and people are looking for things to try, trying these new ideas.
Jake: Like Carol mentioned, experimenting to figure out exactly what style works best with Rust code, A lot of the existing frameworks have copied ideas from other languages, which is a great place to start. But then you need to explore within how idiomatic Rust code works and how does it work in a strongly typed language versus a dynamically typed language and what is just the right way of putting together these types of apps. So I think there's a lot of that experimentation still going on.
Carol: Yeah. If you're looking for a real easy smooth kind of Rails experience, I would wait for writing a web app in Rust today. If you are excited by experimentation and trying new things and maybe you want to try writing your own and maybe you want to try writing a piece of like Rails is made up of so many gems. So there's opportunity for writing a piece of what might become the Rust web framework. So if that sort of thing excites you, this is a great time to get in and try and experiment.
Chris: What is...? I think in the Rust Book, the first like bigger maybe nontrivial thing that you have the readers create is a CLI. Is that correct?
Carol: Yeah, the minigrep projects?
Chris: Yes. It seems like CLI are a good fit for Rust. Not just in general but kind of in the state that Rust is, is at right now also. Are there any CLIs that we would, I would or others would recognize that are built in Rust?
Carol: So ripgrep is one.
Chris: Right. Yep.
Carol: Zola is a static site generator. That's written in Rust.
Chris: Oh, yeah. Yup. I think I saw that. Okay.
Carol: There's like a lot of little ones. The reason that Rust is a great fit for this is its cross compiling capabilities. Whereas if you wrote a command line tool in Ruby because it's interpreted, you would have to make sure that the person you're sending the tool to has compatible Ruby version installed. Whereas with Rust you can cross compile and then hand off the binaries.
Jake: Yeah, which we kind of alluded to earlier with deploying of Crates IO but Rust is... everything gets statically linked at build time and so when you have this thing it is just a single executable that you're very likely to be able to pass around. I've heard some from people who were writing kind of some smaller tools for like their own companies and they were like, "I actually just checked it out on Windows and it built the first time and I didn't ever think about it until somebody asked if there was one to download." So like that's a really powerful ability. Now I mean you can opt into platform specific things and say, "well I want to make use of something Linux specific or MacOS specific or Windows specific and then obviously you have to deal with that at some point. But Rust, The Standard Library is fairly cross-platform and most libraries except for ones that are specific to a platform tend to be pretty good at being cross platform as well.
Carol: Speaking of cross-platform and cross-compiling, Rust is also good for a writing code for embedded devices.
Chris: Oh, right. Yeah.
Carol: Jake's actually done way more of that.
Chris: I've played with like Arduino and this little device called the ESP8266 and ESP32 that has wifi stuff or any of those devices compile targets I guess, or the processor on those compile targets for Rust?
Jake: So the biggest one right now, generally when people kind of say embedded in Rust, they're talking about the CortexM3 ARM processor. That's pretty much the best target right now for Rust. To me like that chip ends up being a little bit more than embedded. It's got all this space, it's got all this abilities. I'm interested in Arduino like you mentioned using the AVR processor. Unfortunately right now... So Rust is built on top of LLVM and LLVM doesn't actually have great support for those chips. And so I'm actually a part of a project that when I... in my copious free time, I try to help where they are supporting that inside of LLVM with the intent of getting it into Rust. And so every few months we update the compiler and try things and figure out where new bugs are.
Jake: But that's my end goal as well. I think the same thing is kind of true for the ESP that you mentioned. I think LLVM support for it is not super great and I think there's another parallel group of people who are working on getting that support as well as getting support in Rust for it. It's funny because most of the work is all in LLVM. Like basically the amount of work inside of Rust to support new platform, at least for the ones that I've seen has been very minimal. It's basically, tell it what LLVM settings to use and you're 90% on the there.
Chris: One thing that seems interesting too is like I sometimes think of a Raspberry Pi is like not embedded, kind of cheating embedded. Because you get this whole Linux environment or OS to work in. But it seems like a $35 Raspberry Pi still has constrained memory. Like you're still limited to a Gig or actually I guess two or four gigs now with the new Raspberry Pi 4. But they have GPIO pins and people do very often use them in projects that are kind of more associated with embedded work. But it seems like that, that thing still has constrained resources and so using Rust on for those types of projects would still be valuable and useful in using constrained memory, but also efficiently using that CPU that's on the Raspberry Pi.
Jake: Yeah. And when, when you start to get into the beefier hardware, like you're talking about, there are some operating system projects in Rust. The most well known is called Redox. But it's actually a really great a tutorial about creating your own operating system in Rust. The person producing it is called Phil-opp. And I forget if that's their online name or their actual name. But you could do something like that with the Raspberry Pi where you basically, you are the entire operating system. That's the best way of getting as much memory as you can, right, don't let anything else run whatsoever. But, yeah. One of the other benefits of using Rust for a Web service. There's some of the White papers on the Rust Website talk about this, but there's Web services that were written in Java using eight gigabytes of memory or something like that. And it was rewritten and Rust and now they take on the order of like 50 or a couple hundred megabytes of RAM just through the ability that you get and so that kind of thing would also apply on something like the Pi. You'll be able to make much more efficient use of your memory and those resources.
Carol: And even on Heroku. I used to work for a company that ran Rails app on Heroku and there was just a base amount of memory that Rails always needed and we would hit memory limits and we'd have to bump up to bigger dynos. And with Crates IO, I sometimes just look at our graphs of memory usage and I laugh because it's just so tiny compared to what a Rails app uses.
Jake: The stat there is that you actually pay more for logs-
Carol: For Papertrail, for storing our logs than we do for dynos.
Chris: Wow, yeah. So you can say, "run Rust, save money." So we've talked about some things that Rust is good for what are some examples that Rust is not a good fit for?
Carol: I think Rust isn't great for prototyping and just writing something real quick that you just want to run once or twice or you're doing a demo or you're trying out an idea and then you're going to rewrite it for production later.
Chris: Like maybe Ruby or Python.
Carol: Yeah, if you're going for pure development speed and if you want to ignore the things that the compiler is trying to help you remember then Rust will get in your way a little bit. I think it's good. And I do use Rust to prototype because often prototypes end up in production. But it can get in your way.
Jake: I think Rust also has kind of that chicken-egg thing going on right now. If you want to do some machine learning, right? Like hands down, basically people are going to use something based on top of Python and a bunch of under-the-hood tools. And so if you want to do that in Rust right now, it may not be pragmatic.
Jake: It's always driven by somebody who says, "it's almost there. If I just put in that little bit of work to get the next thing or wow, if I wrote this in Rust, then I'd get all this other benefits. Let's go ahead and bite the bullet." There's genomics companies out there who are like, "we can process that much more data if we do Rust more pervasively than what we're currently doing. Let's go ahead and try and get some of that ecosystem out there. Let's go ahead and encourage some of these great authors to expand on this or that."
Carol: Yeah. And, and if your code is working, if you have code written in some other languages and it's working. It's doing what you needed it to do. It's making you money. Absolutely do not rewrite it in Rust. I want to be very clear about that. There are people who go around saying everything should be rewritten in Rust, we disagree with that. When Rust benefits would be useful to you, we encourage you to look at Rust and there are foreign function interfaces that can help you incrementally re-write in Rust. Because wholesale rewrites are always risky. Don't use it just for the sake of using it. Have a reason to use it.
Chris: We talked about a few learning resources, but what are some other resources or kind of... What's a good path you would share with someone who's interested in learning more about Rust? And potentially learning to be proficient in the language?
Carol: Yeah, so we talked about the Rust Program Language book. There's also a Programming Rust is the O'Reilly book and I've heard they're good compliments to each other. So if one doesn't quite resonate with you, the other one might. Rust in Motion video course, if you like video learning more than that, if you like trying out code and learning a way to code, there's Rust by Example, is an official resource. There's also Excercism which gives you a little programming problems to try and that you submit for review, which is good for lots of languages. But there's also a Rust track. I started a project a long time ago that I've since kind of pass onto the community called Rustlings. And it's lots of little pieces of Rust code that intentionally don't compile to give you that practice of reading compiler messages and trying to fix them. So you're given this code that's broken and your job is to figure out a way to fix it.
Chris: I like that. It's easier... it's always easier to jump into solving problems than just starting with that like blank page that you have to start writing from.
Carol: There's also the Rust Cookbook is kind of trying to be like, "I want to parse URL in Rust, how do I do that?" And so it gives you kind of a little recipe of how to do common tasks like that. For the different areas like the embedded and WebAssembly. There are books just for those areas. So documentation has always been something really important to the Rust Community. We're really proud of the work that's gone into documentation and that we see documentation as a first class citizen and as an artifact that we need to produce or else like the technical... If you can't explain how to use something, it doesn't matter how technically great it is. So, we take documentation very seriously.
Jake: And touching on that, we talked a little bit about Cargo and that's actually part of Cargo. It's a build tool, it's a dependency management tool. It's also a test runner and it's a documentation build tool and that's all been there since Rust 1.0. These are all things that we take seriously and we say there needs to be documentation. There's actually a lint that you can add in the compiler that will fail your builds if your public API is not documented. That's something you opt-in to
Carol: It's opt-in.
Jake: ... but it is not unusual to see that in well-regarded crates.
Chris: One thing that I was looking for is idiomatic Rust. I knew it had... I wanted to solve some little problem. But I kind of just wanted like a little bit of a nudge or guidance as to, what is the Rust way to do this? And then not only do I know it for that thing, but I can also kind of then repeat that pattern in other places that are similar. Do you know of any good resources of things like that or maybe Rustlings is a good resource for that?
Carol: Rustling... I feel like I mostly wrote those to be broken, so I don't know if I'd look to that for coding samples. But there is the Clippy tool which is named after Microsoft's Clippy. It's a set of lints that are not appropriate for the compiler for a variety of reasons. But it will do things like encourage idiomatic code. It does fun things like if it notices you've written a floating point number that's awfully close to Pi, it'll be like, "hey, the Standard Library has this constant for Pi, you might want to use that instead." So it has a lot of hints and nudges and checks for things like that. And it can often teach you about Rust patterns that you don't know about.
Jake: In the realm of idiomatic style. There's also, a Rust format tool. There's a community agreed upon general style for Rust and Rust format enforces that by default. It is one of the configurable tools. So if you are a strongly opinionated that it needs to be two spaces instead of four spaces or tabs instead of four spaces. Like it's the kind of thing you can change. But I've been pleased to see that most people who use it tend to stick basically to the defaults. Which gives a really nice ability to read a random piece of Rust code and not have to jump all over with your eyes. And that's something that I understand is a touchy subject to a lot of people. "That's my code style, don't touch it." But I'm appreciative that there's mostly a standard.
Chris: Cool. Well, thanks for joining us for the Code[ish] Podcast. I just wanted to mention Rust in Motion, your video series, video learning series again, and we'll have more details about that in the show notes. Are you guys still working on that Rust in Motion? It looked like, it's ready to be used and consumed by people, but it's also still like changing and expanding over time.
Carol: We've finished the first draft of the content. It's still in Manning's Early Access Program, so it's still might change a little bit, but all the content is now there.
Chris: Cool. Well, thanks for very much for joining us on Code[ish], Carol and Jake. And also if you want to check out Carol and Jake's video, the Rust in Motion video series, we have a 40% off coupon here. It's podish19. It will also get you 40% off of anything from Manning who they partnered with for this series.
A podcast brought to you by the developer advocate team at Heroku, exploring code, technology, tools, tips, and the life of the developer.
Director, Developer Advocacy, Heroku
Chris thrives on simplicity and helping others. He writes code, prototypes hardware, and smiles at strangers, helping developers build more and better
Co-owner, Integer 32, LLC
Carol is on the Rust Core & Crates.io Teams & co-authored The Rust Programming Language book w/ Steve Klabnik & Rust in Motion video course w/ Jake.
Co-owner, Integer 32, LLC
Jake is on the Rust Infrastructure Team & maintains Rust Playground. May be best known for being the #1 contributor on the Rust tag on Stack Overflow.
More episodes from Code[ish]
Laura Fletcher, Wesley Beary, and Ian Varley
In this episode, Ian, Laura, and Wesley talk about the importance of communication skills, specifically writing, for people in technical roles. Ian calls writing the single most important meta skill you can have. And the good news is that... →
Jim Jagielski and Alyssa Arvin
Jim Jagielski is the newest member of Salesforce’s Open Source Program Office, but he’s no newbie to open source. In this episode, he talks with Alyssa Arvin, Senior Program Manager for Open Source about his early explorations into open... →
Lisa Marshall and Greg Nokes
This episode of Codeish includes Greg Nokes, distinguished technical architect with Salesforce Heroku, and Lisa Marshall, Senior Vice President of TMP Innovation & Learning at Salesforce. Lisa manages a team within technology and product... →