Check out a free preview of the full Rust for TypeScript Developers course:
The "Install Rust" Lesson is part of the full, Rust for TypeScript Developers course featured in this preview video. Here's what you'd learn in this lesson:

ThePrimeagen sets up a new project with TypeScript and Rust. Strict type-checking rules are enabled. Cargo, Rust's package manager, initializes the Rust project and a Git repository.

Get Unlimited Access Now

Transcript from the "Install Rust" Lesson

[00:00:00]
>> So we're gonna go over a little bit of a basic setup to make sure that you guys can have everything running on your system, you're feeling good, and we can start programming. So for those that have not set up TypeScript or Rust yet, this will hopefully do everything for you.

[00:00:14] So create a folder wherever you wanna create it, your favorite. Most favorite place for me, that's gonna be personal/rust-typescript, however you want to set it up. Then inside the folder, we should probably execute a few things. We should create an npm. We should npm install ts-node typescript nodes/types.

[00:00:32] You can install your favorite version of a TypeScript compiler, SWC, esbuild, whatever you wanna do. If you're proficient enough to build your own setup, we're gonna be executing TypeScript a few times, so do it the way you wanna do it. So I'm gonna just copy all of this.

[00:00:49] I'm gonna go over to my rust-typescript, and I'm gonna npm init, npm install, ts-node typescript, and node/types, and then tsc init. And then because we're such good, okay, now.
>> It's at type slash node.
>> My goodness, I had it backwards.
>> My goodness, yeah, npm, I knew that, okay, it's types/node.

[00:01:12] Okay, so sometimes I type examples in from my brain and not copy them from the command line. So things happen, I'm just a victim right now. Okay, tsc of my own short-sightedness. Okay, so there we go. Create a tsc file. It's always good to have one of those.

[00:01:27] And since we are such amazing safe programmers, let's jump down to the strict portion of TypeScript. And let's make sure we have all the things super safe, right? Because we are super safe programmer, so I'm gonna go tsconfig. And I'm gonna go all the way down to strict, and I'm just gonna take all of these amazing options.

[00:01:48] Matt Pocock would be just so happy with me right now. And go to right here. Take them all out. There we go. Look at how beautiful that is. Look at how safe we are. Practically Rust already. You just got to go down on it. I mean, technically, you don't have to do this.

[00:02:05] I just think it's really good TypeScript practice to always make sure you have the most strict version of TypeScript because it's gonna save you, especially this one. This one's very interesting. There's another one. This one's super interesting as well. It changes how TypeScript works a little bit. Great times, all right, you can enable, disable, whatever you want.

[00:02:25] You don't have to do any of this. Next, we need to install Rust. So here you go. You can just go look for install Rust. You should find this very benign script on the Internet. Don't worry, it's not a big deal. You should always execute scripts you find on the Internet.

[00:02:41] Just pipe it right into your shell, maybe throw a little sudo in there just to really assert your authority of trust. It's Rust, okay? It's reliable. It's gonna hold you safely while it does whatever it does on your system. So to know that you've done it correctly, you should be able to call cargo init in the same folder, and now you'll have a Rust project and a TypeScript project all in the same folder.

[00:03:02] And of course, if you are using Vim or Telescope, it is always good to make sure that you have all of your git status stuff set up correctly. Cuz when you do a cargo init, it does git status. Notice that I don't have, say, node_modules ignored right now.

[00:03:17] So you might wanna make sure that your gitignore is nice. So I'm gonna add in node_modules, look at that. I'm gonna commit everything cuz it turns out INITIAL COMMIT. Some fuzzy finders don't find over files unless they're committed into the Git repository. So, just so you know. So for my VSCoders out there, you may wanna disable inlay hints.

[00:03:45] They're very distracting. They pop up all over the place as you type. There are really truly poor user experience. Everyone I've ever seen use it plus with Rust, gets confused, and they're just everywhere. And they're brightly colored and they glow. I have no idea who made them. But if you have neovim and you have inlay hints on, nice job.

[00:04:05] It actually is super cool to use ghost text at the end of the line so it doesn't interrupt your code or its spacing. It's beautiful. Also disabled Copilot if you have Copilot. I know Copilot is pretty trendy these days. The problem with Copilot is that when someone else types the program for you, you may be better and better at recognizing valid code.

[00:04:23] But you yourself will have absolutely no idea how to write the code by yourself. If we were to turn off Copilot after the end of the day, and you try to write the struct, you probably wouldn't even be able to write the struct in a simple implementation, because you've just let somebody else write it for you.

[00:04:36] You learn heavily by interacting with the physical world, so interact with the physical world with these beautiful ten fingers that you have.