Skip to main content

almost 3 years ago Syntax Podcast

Rust for JavaScript Developers - Node vs Rust Concepts

Wes Bos

Wes Bos Host

Scott Tolinski

Scott Tolinski Host

Topic 0 14:07

Rust documentation is very code-heavy and functional, less hand-holdy than JS

Scott Tolinski

so, like, we kinda got into this with typing. In in JavaScript, you can get, like, TypeScript for static typing. But in in Rust world, it is very TypeScript like static typing.

Wes Bos

arguments,

Scott Tolinski

And a lot of times the the type syntax for defining types on things

Scott Tolinski

it it is it can take these comments and generate the, t o m l, is via, like, pattern matching, Sometimes, Wes. So you can you can do a call for something and get a result back to it. And that result

Wes Bos

How do you do examples

Scott Tolinski

And likewise, Because you do sometimes see it in it's not just used in the import statements. It's sometimes used inside of code.

Scott Tolinski

in your That's just my own personal preference, but So similarities, Instead of having a 1,000,000,000 options do a 1,000,000,000 different things, you have a, like, a really happy path for everything. And that happy path is basically You also have PNPM or with Rust But you have this cargo here. You have,

Scott Tolinski

It's like a I don't know when did a sync await drop in Rust. And it feels very much like JavaScript and that, structs, to pull out

Scott Tolinski

Let's talk about memory safety.

Scott Tolinski

than any other type system that I've used personally,

Scott Tolinski

Docs based on different little helpers, So,

Wes Bos

loose.

Wes Bos

Markdown

Wes Bos

in comments. It seems a lot less rigid than JSTOC. You simply just put a bunch of single line comments, And sometimes it's frustrating, like, can't we just settle on 1?

Scott Tolinski

describe your code, essentially, the parameters and arguments. Yeah. You don't have to do that here Because it's statically typed by default. Right? And so what ends up happening is your docs for a full archive of all of our shows, So Okay.

Scott Tolinski

and your comments end up kind of, like, morphing into docs And comments depending on how you like to write your code. Yeah. And that not only, like, helps Then you use double colon. The double colon specifies that you're you're pulling out, it's it's like, you're pulling out essentially a module, accessing I think first and foremost, you could see, like, I mentioned that JavaScript and Rust can feel very similar. And I'll post a, some in the show notes here just a Quick little hello world function. Where in Rust, it's f n hello, or use use STD colon colon time colon colon and then another module.

Wes Bos

pound

Scott Tolinski

together.

Wes Bos

And you can just Triple back ticks for code examples and stuff. Oh, that's nice. That's way better than like, JSoc is good, but you have to know the syntax, a massive

Scott Tolinski

practice dot r s or Rust by practice. And this shows you just kind of a general idea of the comments that you could have for docs.

Scott Tolinski

You do have things like generics, the match keyword in Rust is kind of like a a bigger topic that I would wanna talk more about. Either way, if you run something the way you do it rather than in Rust.

Scott Tolinski

end up being really nice because it's all, you know, comparatively than just straight up JavaScript. Right? You want to be building it. Some more intense stuff than than you could see here very easily

Wes Bos

in your code. It's it's just like

Wes Bos

And this seems a lot more some code Do you know red green?

Wes Bos

and descriptions

Wes Bos

And then you do pound

Wes Bos

panic, pound

Scott Tolinski

memory safe.

Scott Tolinski

And it does feel very JS docs like, But when you're writing comments into your code, Other times you'll see use, it was like, this is like how similar they can be. Just f n verse function and then print line instead of console log. Other than that, they're effectively You are sometimes pulling in a module or a method or a function instructor. You're sometimes Pulling in things from submodules.

Scott Tolinski

take more control over your application. Again, as as web developers, it's, like, very, very rare that we're thinking about Right. Right? What about, like, promises, async await in Rust? What does that look like? I just did a quick Google. That's called the future. Is that true? Yeah. But there is a sync await for, like, $100 feels more like TypeScript the cottage boss.

Scott Tolinski

But it's it's all fully documented, all your methods and everything. And you're saying those are all generated from the Rust code

Scott Tolinski

Predict how things might work knowing that it is TypeScript like in how you define your types.

Scott Tolinski

Like, type your code

Scott Tolinski

This is one that we could spend a whole episode on, but where Because you're having to specify

Scott Tolinski

to Well, I mean, they they sorry. They they mostly do. I wanna say that.

Wes Bos

example,

Topic 1 10:27

Rust community seems to have standardized on using Cargo, unlike Python/JS communities

Scott Tolinski

Generate documentation

Scott Tolinski

I found to be interesting

Wes Bos

Isn't is there alternative things in the Rust community, or do they just use cargo

Scott Tolinski

and have it be parsed as markdown directly in your code. There's some neat things there. But for the most part, you know, one thing that it's more obvious, I suppose. I we should maybe do a dive at some time in the differences between TOML and YAML. But,

Scott Tolinski

from your your code itself, It is just slight it's it's kind of like bizarro world,

Scott Tolinski

pretty good documentation, So cargo runs your code as well. Cargo run is the equivalent of, like, NPM crates.

Scott Tolinski

it is very code heavy. But I can guarantee that if you Spend some time in here and, like, really learn how to for a documentation for a library, and it might Very much look overwhelming for you pretty quickly because and that made me a better TypeScript developer. But it also made me a better Rust developer knowing that I, you know, could at least read this documentation A crate is a package.

Scott Tolinski

see all of the methods and structs and whatever that's available anywhere in here. Allows you to see all that stuff. It allows you to even have a quick copy to be able to use it in your code like a copy paste thing. So it's very nice and functional.

Scott Tolinski

Cargo to publish your docs. Right? And with docs dot r s, in JavaScript world for, let's say, like testing, documentation because it is much more of a technical style documentation or JavaScript and they're the same syntax as you do in TypeScript.

Scott Tolinski

is that the docs that get published looks like on here, and it's kind of no fluff. It's not

Scott Tolinski

So next step is let's talk about, like, documentation.

Scott Tolinski

a lot of the things in the Rust world elaborate upon certain packages that, you know, you might need to tell it, hey. Use this feature or this feature from This this specific package to use more things from this. Oh, and one last1,

Scott Tolinski

a a little you know, somebody who's getting into Rust from JavaScript,

Scott Tolinski

And this level on the web aren't necessarily what I would describe as, like, pretty or well designed.

Scott Tolinski

Comments and, Pattern very frequently. Because as I tell you this, when you sometimes have submodules that are defined with a slash, Right. You could say Svelte The fact that we don't have everything as objects makes a big difference in how we code. So, the all of the happy path to go on. And if you can get a happy or a hello world it. Up and running in Ruston in no time whatsoever. You know, that is a good first step, but there is a lot of things that will trip you up along the way That I would love to get into in further of these episodes, things like things like memory, What is these Colons for Yeah. Well, this can be the last thing because we're getting into, 29 minutes here and then we can, you might hit a page

Scott Tolinski

generated docs, it's very much that style.

Scott Tolinski

This is the type of page if you ever link to or if you're watching the show and you wanna click through through some show notes, it's very, you know, Generate like, when we had JSDoc Functions or methods on a thing where the dot is for who is into higher level languages, getting into the concept of Threads is a great way to, So

Scott Tolinski

But at, Like for And that's not necessarily how it works here. So it's used in place of the period for name space paths, No JS land? Mhmm. I, like, kinda brought it back. And when I posted it, everybody's like, this is how Rust does it. Yeah. Yeah. And I and I, like, end up liking it a lot. You know, the The match keyword, again, I I don't wanna get too deep in the match because that's a a can of worms for this episode, especially if we wanna keep it at very basic level.

Scott Tolinski

for everything? Everybody uses it. I'm not enough of a Rust head to know if there is such thing as an alternative, but I I I mean, I I don't think so. I think that it is you know, there there's recently been, like, a an entire fork of Rust called the it. Which is an entirely different bundle of drama and stuff like that to get into. But Really? Yeah. But so I I don't know. Because Cargo is so tightly integrated into everything. I can't imagine there is something else, but I don't look, again, I don't I'm not enough of, rather than it being some sort of weird syntax.

Scott Tolinski

It links to their source. It allows you to,

Scott Tolinski

Let me I'll post this 1 in the show notes. This is a specific package, just a random page from a random projects package.

Topic 2 02:33

Red Green was a hilarious Canadian TV show about duct taping everything together

Wes Bos

Fish. And it. I got a pair of deer antlers and all kinds

Wes Bos

Trying to buy it because I don't I don't know how you legally buy this type of stuff, but I wonder if you could permanently rent it. Yeah. So she She's like, sorry, I'm

Wes Bos

and he would do, like, the most hilarious,

Wes Bos

So I ran and then I knocked on the lady's door and she's like, I'm sorry. I've had offers

Wes Bos

I guess kinda like redneck y stuff. Mhmm. But it was, like, very wholesome, very Canadian,

Wes Bos

for instead of $30, I've had offers for

Wes Bos

like, it was like, how do I describe who Red Green is? If you Google Red Green Possum Lodge, you'll see what I'm talking about. So

Wes Bos

But we did find, like, 2

Wes Bos

the rules and whatnot, so I did get to buy a nicely mounted set of trout. I wanna,

Scott Tolinski

of interesting stuff. Gas cans. Wow. We we were on the hunt for a taxidermied animal it. Our our office went at one point at an office I worked at, and there is some wild stuff available. It's you're not allowed to buy it in In Canada. And I I once from your code. And that's something if you ever go on to, and that actually comes in handy. You can write

Wes Bos

huge lake trouts once at a thrift store.

Wes Bos

It was a show where they did, like, skits, 500 from, like, movie sets and stuff like that,

Wes Bos

taking the money. I don't care that you just drove here.

Wes Bos

deer antlers and geese and fishing equipment and stuffed chickens and Yeah.

Wes Bos

And often the thrift stores don't know Right. That's what I'm saying. Yeah. The order is what you ordered. Write it backwards, and there's there's snippets that you could you can do to write the package name first. But,

Wes Bos

saw

Wes Bos

on marketplace,

Wes Bos

And I freaking loved that show growing up. I thought it was the most hilarious thing in the world. And he their set, The set that they had was called Possum Lodge. If you Google Possum Lodge, red, green, you'll see what I'm talking about. And that's kind of my end goal with this office is just

Wes Bos

us. All kinds of random

Wes Bos

and he would do things like Duct tape everything together. That was the way he and his his tagline is if if women don't find you handsome, they should at least find you handy.

Wes Bos

And it was like 5 foot long pike, like jumping out of the water mounted. And someone was selling it for like $30.

Wes Bos

pike

Topic 3 05:13

Found a $700 snare drum for $100 at a pawn shop in Montana

Scott Tolinski

Cargo does it. Do some work to do that. Yeah. And and typically, when you're using async await, it's the exact same, the entire idea of Memory usage within Rust. So I'm not gonna touch that beyond just saying there's no garbage collector in Rust like there is in JavaScript, Actual value of that snare drum, and I still have it. It's my favorite my favorite snare drum. That's amazing. I find I find, like, pawn shops is the package that you publish. So when you do cargo publish, it takes your code and puts it onto something called crates that's up that's what's up with the double double. And so you'll see it all over Rust world. Just know that

Scott Tolinski

if you were installing it's still single threaded.

Scott Tolinski

start and running a script even though that script just runs Usually like Node or Vite or whatever. Cargo

Scott Tolinski

So I ended up just calling every Not anything that we're typically worrying about as web developers here. But if you're the type of person, to do testing.

Scott Tolinski

cargo build builds your project. It's like a in a in a way to that you can ship the project. And when it's built and shipped, is that what a crate is or what's a crate in Rust's world? Welcome to Syntax.

Scott Tolinski

So if you do cargo doc, it can give you documentation, like, what else Like, it basically is forward slash

Scott Tolinski

based on how you're writing your code, it can publish libraries. So if you're writing a library in Rust, or for enum values. Right? If you had an enum that had names in it, You could say name colon colon Scott to pull out an enum value.

Scott Tolinski

jest. You have mocha. You have You have all these different, things that work together Next is, concurrency. JavaScript is single threaded, and Rust has support for multi threading. So I hope that helped. Sometimes it's hard translating some of these things from one thing to another thing. But, again, it's all very neat. And, I've had a lot of fun writing Rust code myself, and and I hope to dive further and further into this this world and create some cool stuff. Beautiful. Alright. Thanks everybody for tuning in. We'll catch you in the next one. Peace. Ace.

Scott Tolinski

at a Pawn shop in Bozeman, Montana.

Scott Tolinski

snare drum for nothing. These people do not know what they have, and I got the fanciest snare drum. I had to call the I I ended up it. Calling because we left, and I was like, man, I wish I would have bought that snare drum. I couldn't fit in my suitcase.

Scott Tolinski

you have NPM as your package manager. NPM is its own thing.

Scott Tolinski

File in Rust is cargo.toml, you know, deep into the Rust world. I'm more of a hobbyist Rust developer.

Scott Tolinski

And you're going to see this same

Wes Bos

Other package managers that people we have, PNPM and Yarn. And then you look at the

Wes Bos

cargo because you look at JavaScript landscape, and obviously, we have NPM, but then other there's

Scott Tolinski

a signature series high end wooden rimmed Yamaha snare drum You can pick your package manager, pick your testing library, whatever.

Scott Tolinski

yeah, TOML. Cargo. TOML is where you put all your dependencies. And not only that, you can, like, tell it a specific features that you need to use to, like, read code in Rust world, but it also helps The documentation is built in memory safety without garbage collection. And what that means, we would wanna be getting way deeper into Rust can feel very much like TypeScript at times. It can feel very much like JavaScript at times.

Scott Tolinski

to start, I think we should maybe talk a little bit about Things that are in Rust first JavaScript for instance. In Node world, in fact, let me I'm I'm trying to find a good one because I was just On a a big project You're going to see that all of the packages, Right? Because because Rust itself is fully typed? Correct. Yeah. Rust is fully typed, and we'll talk a little bit about what that that looks like to do.

Scott Tolinski

a massive amount for you beyond just fetching your dependencies.

Wes Bos

are never a good deal. Every time I go into 1, I'm like, I can get this cheaper at the store.

Scott Tolinski

you would use Cargo to publish that library.

Scott Tolinski

There's also the main package

Scott Tolinski

So, TOML is one of those things that's kind of YAML esque, but, to pull something out the rusty equipment in the shed. Let's get into some rusty code and and talk about Rust and JavaScript.

Wes Bos

Python landscape, and there's All kinds of different things in the Python landscape.

Scott Tolinski

a package like Express in JavaScript.

Scott Tolinski

can Cargo do? Well, Io, string. And if I wanna access string methods on that you do my string dot the method. Just like you would in JavaScript.

Scott Tolinski

you have v test. You have that they had a $700 snare drum. Yeah. It's a beauty. Alright. Let's get into instead of rusty, Here's from the module.

Wes Bos

Like, why is this this so much? So I think they've they A lot of them know what they have. That's amazing that they didn't know

Scott Tolinski

So I felt like what we could do is probably get us. A few different episodes about this going into different aspects of Rust versus JavaScript. So if you're starting to get into Rust and you see some terminology around or you want to Try it. You at least kind of know what's what and where you're at.

Scott Tolinski

run is actually how you run your projects.

Scott Tolinski

inside of Rust. So like NPM. Beautiful. Cool. So that is Cargo. Cargo does just about Everything as you will see. It it it can publish your docs. It can publish your library. It can Yeah. Run your tests. It can get your fetch your packages, publish your packages, build, all that That seems to be like everybody uses

Scott Tolinski

as a part of the package manager.

Scott Tolinski

Cargo, Yarn, but NPM is the package manager of Node. Essentially, comes when you install Node.

Scott Tolinski

And I was there with my family going snowboarding. And when I saw this thing, And, I mean, often used inside of code. Us. In places in which you'd typically think like a period would be. Right?

Topic 4 23:38

Wish JS imports worked like Rust's use statements, specifying package first

Scott Tolinski

Drill down into what you want. Right? And what that makes so much sense because every single time you don't get the auto completion that you'd want

Scott Tolinski

it's basically

Scott Tolinski

method, and everything. And that's because in JavaScript, everything is an object.

Scott Tolinski

In the Rust world, you use the use command So it's it's used for name spacing really to pull things out of a name space Where a dot, a period One time I found

Scott Tolinski

Colon

Scott Tolinski

when they're looking at Rust it. Because it looks so foreign for some people who are used to either doing a forward slash or a dot in JavaScript. Right? Yeah. That's actually one thing I found about Rust

Wes Bos

pretty easily, which is not necessarily

Scott Tolinski

for calling functions or static methods on things And then you specify

Scott Tolinski

While we're here talking about this colon, we can wrap it up with, like, what's up with the double colon? Like, what is it? Like, how what does it actually do inside of RustWorld?

Scott Tolinski

And the reason is is that just like in JavaScript,

Wes Bos

instead of what we have. But the the auto import tooling obviously makes it better, but

Scott Tolinski

So in the example I have in the show notes, it's STD for the standard library.

Scott Tolinski

You'll see the at these use statements, they go in the same place as an import statement does right at the top.

Wes Bos

Does that track? Yeah. Yeah. It makes sense. Yeah.

Scott Tolinski

colon hash map is the actual package that we're pulling out of here or the actual methods or functions that we're pulling out of here.

Scott Tolinski

first we have a tooling because it's not great. Yeah. So, you know, one thing you'll see in rest is, occasionally, Head on over to syntax.fm that I've been working on. So it. The module.

Scott Tolinski

the module and then specify

Wes Bos

Yeah. I mean, it would have made a lot of sense to do the package name first,

Scott Tolinski

You know, if you're accessing a method or something, there's caveats there. Okay?

Scott Tolinski

or you're diving into a module. It's it's very similar to how we often use the period inside of JavaScript and TypeScript.

Scott Tolinski

you you're typically using A crate You'll find that over time, you'll not only get better at reading Rust code, learning Rust itself, but also even it'll Oh, pay dividends in getting into JavaScript

Scott Tolinski

to basically say, hey. This module is gonna become available in this library or in in this file. Right? like a, a method, you can run that function or a function. You can run that function and then

Scott Tolinski

So you so we have used STD colon colon and then you have a sub module named collections It well, the way they handle difficulties.

Scott Tolinski

So like, let's say we go to any package on crates. Io.

Scott Tolinski

Here's a sub module, and here's the thing I actually want.

Scott Tolinski

the package name.

Scott Tolinski

colon colon c s Oh, read me. And they all end up having I find that to be really nice to use. So much to the point where, like, instead of functions or methods on an instance of a thing.

Wes Bos

import.

Wes Bos

for other languages that have different syntax or different order of operations.

Scott Tolinski

In a JavaScript world, you're always using the period. Right? No matter what to access anything, sub sub module, Today, I'm feeling a bit rusty. That's right. We're talking about Rust on docs.rs.

Scott Tolinski

But the one thing you'll often see is occasionally,

Scott Tolinski

transitions, and that pulls in a transition from the transitions module of Svelte.

Scott Tolinski

So if it looks weird to have so many colon colon thing, colon, colon, thing, colon, colon, thing. Just know that you're drilling in deeper into submodules So we'll we'll talk about that later at a later date. Especially, if if people like this episode, we can do many more of these because There's a lot here to talk about. Mhmm. So, you know, one thing I wanna talk about real quick is some of the syntax stuff. So, you know, is a nice language for people who want to get into a more intense world you know, like I said, there there's us so much here at a high level for JavaScript developers. We could spend a few episodes going over all kinds of things. So can do testing. It can build your documentation.

Scott Tolinski

If you're a Rust head or, you know, somebody very experienced, I'm speaking on a very, a very back level here. K? We don't need to get too deep into this syntax because match

Scott Tolinski

So

Wes Bos

The same

Topic 5 00:00

Transcript

Announcer

the craziest,

Wes Bos

down the road and

Wes Bos

I'm going to put it somewhere else. I mean, you could build a little stand for it. Yeah. I think so. It's got to look a little bit more

Scott Tolinski

basic, basic level. So there's no expectation that you've ever done anything in Rust Or even we'll do anything in Rust, but maybe it's a good idea to learn some of just exactly how these systems can be a little bit Different. My name is Scott Talinski. I'm a developer from Denver. And with me, as always, is Wes, Right? pawn shop in Bozeman

Wes Bos

I'm more thinking, like,

Wes Bos

garage for, like, 40 years.

Scott Tolinski

It. And we're gonna be doing so at a very basic,

Wes Bos

lean it against a shovel or something like that. Yeah.

Announcer

Monday. Monday. Monday.

Wes Bos

More natural than that. Like, I'm trying to do you know who red green is? Like a So you're not, like, you're not creating a new thread by doing a single await or anything like that. Yeah. That's it's kind of similar to JavaScript in that I think a way to still single threaded. But if you want to go multi threaded, you have to explicitly And I was like, I'll be right there because it. Because you're not you're not supposed to be able to sell this kind of stuff because it's otherwise, people start killing animals when they shouldn't be.

Wes Bos

sold sold sold because I'm trying to figure out my camera angles in this office, and

Wes Bos

It's not working, but

Wes Bos

It's pointed right at the crack of the corner. So I was like, I need something to go in the corner, but I'll say the bottle is

Announcer

Open wide dev fans, get ready to stuff your face with JavaScript, CSS, node modules, barbecue tips, get workflows, breakdancing, soft skill, web development, the hastiest,

Announcer

Boss, and Scott

Wes Bos

Blue ribbon bottle. How is it glass? Yeah. It's got beer. So we were just, like, driving

Wes Bos

Full glass. And the guy said it has been sitting in my in my

Wes Bos

wooden crate. Yeah, that might work. Yeah. Like a wooden.

Wes Bos

It. And she's like, there's a huge paps blue ribbon bottle, and it's probably

Announcer

the tastiest web development treats coming again hot. Here is Wes, Barracuda,

Wes Bos

And he's, like, $10. I was, like, sold So that is one of the weird things.

Wes Bos

probably 3 feet tall,

Topic 6 20:45

Rust error handling via pattern matching is similar to JavaScript promise handlers

Wes Bos

in, oh, in TypeScript

Scott Tolinski

Rust thrift store finds, Wes, Or like consignment fines. I know this is getting away off topic here. Let's let's get it.

Wes Bos

So I wrote, like, a little function that would wrap a promise call, and all of the stuff that you would do with JSDoc in Rustoc? Is there like a syntax for comments Or what does that look like? So I've linked to a post from,

Scott Tolinski

This is another one that I actually like way more in Rust you can publish your docs really easily on what's called docs c s dot r s using, And This is kind of what all the documentation So the reason why this is so good is because it is statically typed. With JS docs, you have to, which is what what does tamil stand for? Tom's Tom's own markup.

Scott Tolinski

brackets, print l n, exclamation point, and then just a string. And that's your equivalent of function hello is console logging hello, world. And if you look at these 2 right next to each other, these very basic functions in Rust And in JavaScript, you can see

Scott Tolinski

parenthesis, So, you know, oftentimes, that that that colon colon, I think, can, like, really throw people off Mhmm. I I guess it's not a total can of worms, but it it's it's a more complex topic than maybe I wanna get into right now.

Wes Bos

when I posted

Wes Bos

and then it would catch the error or catch The successful result, I'll return both of them in a tuple, meaning that it's an array. First thing is the error. Second thing is the actual result. And then you can just say if there's an error, It's so much better than having to, like, have the scope of try catch. And it's kind of a weird or even a promise dot catch

Wes Bos

on the end.

Wes Bos

making the

Wes Bos

about

Wes Bos

I like that Versus other languages is that I can read it. As a JavaScript developer, I can jump in and reason about it

Wes Bos

Syntax a lot better of all having it all top level. That's kind of what we used to have in, like, callback world in

Scott Tolinski

if statements just how much your skills may translate in some ways. But Let's get into, like, the import syntax. Okay?

Scott Tolinski

or even like a switch statement template tag in Svelte World, I I would like them to do something like match.

Wes Bos

result in the error top level.

Topic 7 18:17

Async/await in Rust is single-threaded like JavaScript, not multi-threaded

Scott Tolinski

which is honestly one of my least favorite things in JavaScript Anyways, I hate the whole try catch thing.

Scott Tolinski

Yeah. And then via pattern matching, you're essentially it's almost like a switch statement.

Scott Tolinski

match Or the okay or the error and then handle those accordingly. So it is very much kind of like

Scott Tolinski

it it's kind of like, you know, in in,

Scott Tolinski

because some things that you would expect to work do not work. Other things, you know, JavaScript has garbage collection, Rust is, Work exactly like you'd expect them to, and some of that aspect can get you mixed up. And other times, it can help you push through some learning Cargo is the package manager for Rust, and you see Cargo so we can get all of that and more in the next one where we talk about how this stuff is different than JavaScript.

Scott Tolinski

then and a dot catch. And it's kind of like that, but not chained as a method to the end. It's sort of like, hey. We have this result, and we're matching this result to either be an okay or an error state. Yeah. It was Where in JavaScript, that would always be duration dot from millis. But because duration is the namespace itself, And don't forget to subscribe in your podcast player

Scott Tolinski

Another interesting thing in Rust is error handling. There's no, like, try catch, In

Wes Bos

grabbing a file or something. The await syntax And Rust is really interesting. So instead of putting away in front of an asynchronous function, you tack a dot await onto the end of your function call.

Scott Tolinski

an error or an okay.

Scott Tolinski

request. You're going off and,

Scott Tolinski

exceptions the same. Right? And that's that's one of the reasons why I think You'll be able to see they all have But it is, This is the exact same concept.

Scott Tolinski

situations in which you would use it in the JavaScript world. Right. You're doing an HTTP a ton of different integer types, 2 different flow types, developers. We're gonna be comparing some of the stuff that you might have used in the JavaScript ecosystem to the things that exist in the Rust ecosystem.

Scott Tolinski

Yeah. Yeah. And and it's funny. There's, like, in in Rust world, especially compared to JavaScript. So one thing you'll notice, especially when you get into Rust code at all, Is that there are moments where it can feel very JavaScript like. And then there are moments when you see things like that Or we'll talk a little bit about, like, the double colon syntax or the use syntax or any of that sort of stuff where can either contain, because it follows the order in which I want the JavaScript imports to run. So in JavaScript world, let's say you had Express. Your import Express from Express.

Topic 8 29:28

Double colon in Rust is like dot in JS, but for static methods vs instance methods

Scott Tolinski

or drop a review if you like this show.

Scott Tolinski

not Like some instance of a a thing, you're able to use that Rust world, you have cargo. Cargo is the test runner and it comes So I wish JavaScript imports work like this where you first specify you have this So A $700 function directly Did you grow up with Red Green? You know what? We I don't know if that's something that we had, but I've heard the name. I I only have Probably heard the name through association with other things. But, no, I don't really know much about Red Green. So I know Tom Green. When when we were growing up, we had the show on Canadian television called Red Green. And very, very frequently in the Rust world. Because unlike in the JavaScript world,

Scott Tolinski

There are a lot of similarity TypeScript It's not A super scary beast even if it can look intimidating at first.

Scott Tolinski

Whole world that is kind of really encapsulated as being And found it, and they shipped it to us. It was like I ended up paying, like, $300 or something for it, but it was still a, you know, nominal price compared to And likewise with Rust, you have Cargo.

Scott Tolinski

It it's if you see, like okay. Here's an example for some code I just have sitting in front of me from, Yes. Here I am. Did you see my new beer bottle that I got? No. But I see the Snow Goose Lane sign and I love that. But that is a big papsed Tom's obvious minimal language, and that is Tom Preston Warner, a former guest on Syntax who created TOML.

Wes Bos

And, we should I Probably do an entire show just on the, like, basic types of Rust. Oh, brother. Yeah. There are Oh, brother. 13 different a Thirteen different base types including,

Scott Tolinski

duration. Duration is the module. You'd see duration has been imported, then you're using duration colon colon from millisecond, from millis, and then a number, Yeah. The thing you want first from the module. Wherein in Rust world, use yeah. Why Why why did they not choose to do it that way in JavaScript? Or even just from the package name, it. Methods on an instance of something. Right? So you create an instance. You create my string is an instance of string. Right? My string. So I have my is used for,

Scott Tolinski

from duration here.

Scott Tolinski

and all kinds of things. So we can talk it extensively about types in another episode. In fact,

Scott Tolinski

And those things can come in way handy when you're learning this stuff because you don't have to make those choices.

Scott Tolinski

variables, you'll see use STD colon colon and then

Scott Tolinski

Rust Rust team stuff. So the Rust docs, crates dot io, promises in JavaScript you can do a dot the double colon

Scott Tolinski

So things like the the typing of things, you know, how similar it is to to JavaScript.

Scott Tolinski

Cargo and Dot I o, which is the package registry in more of a hand holdy style documentation.

Scott Tolinski

I think that would be a good place to end this one because the very next thing I have in my notes here, Wes, is types,

Scott Tolinski

So high level, It tells you the functions.

Wes Bos

that's exactly what I was gonna ask you. I'm I'm it. Super curious about what does an array like is do you have maps? Are there different kinds of numbers? Caitlin's like, oh, they turn around. There was, like, a little yard sale. Like, not like a Saturday morning yard sale, but, like, some guy has stuff for sale it constantly. Not like a Saturday morning, Yarns. No. Just like a somebody in your house on a heavy traffic street.

Scott Tolinski

I know there's a lot of stuff here. But, you know, I you know, I think I wanted to give a real high level overview, especially for this first one is, like, What are the differences? And, you know, the big thing here to think about if you're looking into the Rust world is that comparatively to Node. Js or to JavaScript,

Share

Empowering developers for over 286196184942 milliseconds!