Skip to main content

almost 3 years ago Syntax Podcast

Rust for JS Devs — Part 2

Wes Bos

Wes Bos Host

Scott Tolinski

Scott Tolinski Host

Topic 0 28:20

Vectors vs arrays

Wes Bos

of the same type.

Wes Bos

you probably would want rid. Stick this thing wherever I want, and I can just grab it and move it. I only have to have 1 for the entire gym, and I can bring it with me wherever I want. That's it. Yeah. I Yeah. Yeah. I I just use the pop socket, and that would be great if that was magnetic. You could just magnet to anything like that. Oh, yeah. You had Do you you still use the pop? Didn't you buy the And you have a VEC

Scott Tolinski

and a hash set, Which is a collection of unique values implemented as a HashSet. So you could think of these as sets and

Scott Tolinski

maps and it can convert Boolean that you can pass in? I think at that point, you would use while doing a for in.

Wes Bos

Most cases. Is that right? I I personally end up using a vector way more than

Wes Bos

A fixed size

Wes Bos

That can

Wes Bos

where rid. Detecting that and saying, hey. You're not running anything else, are you? And if you quit Zoom, it will will tell you. But it's it's bizarre, so, hopefully, I can get it pinpointed. Yeah. Rid. It it's so weird that it's only Chromium based browsers in literally every Chromium based browser.

Scott Tolinski

resizable.

Wes Bos

a vector

Wes Bos

be expanded or contracted.

Wes Bos

in

Wes Bos

We have a tuple, which is could be mixed types

Scott Tolinski

what we have in JavaScript where you can add, remove things, whatever. So

Wes Bos

or vector And that is

Wes Bos

And explicitly known the length.

Wes Bos

So

Wes Bos

So I might have 10 numbers.

Scott Tolinski

So something to note here is that an array as defined is a fixed size, right, where a vector is dynamically

Scott Tolinski

the other 2 options.

Scott Tolinski

in JavaScript.

Topic 1 14:11

Pattern matching with Rust types

Wes Bos

The best way I've ever heard it

Scott Tolinski

To,

Scott Tolinski

direct our responses and things like that. It also has the, Yeah. Definitely 1 you'll encounter a lot. And then there's a hash map, which is a collection of key value pairs implemented in a hash table the as keyword, but you can convert number types from one number type to another using the as keyword. What about if you're writing a function in Rust old profile,

Topic 2 11:43

Ownership and borrowing

Scott Tolinski

So statically typed. It's also strongly typed as in the type of every value is strictly

Scott Tolinski

You can't get around it. You have to if the thing is the thing, it must be the thing at all times.

Topic 3 49:20

Sick picks

Wes Bos

fobian material is good at cleaning.

Wes Bos

And it's great because you could just bring your phone around

Wes Bos

the where you have an ID,

Wes Bos

Rid So I put, like, a disc on the treadmill. I put a disc on kind of like the stretching area.

Scott Tolinski

rid. I'm I'm fine with this.

Wes Bos

I'm not one to, like, buy Expensive things like that, but that stuff is awesome. And you can't it's not replicated. It's not just Dawn and and alcohol. It's it's they've rid. They formulated something something else there. It works really well. I like it still. I'm still using it. It's really good.

Scott Tolinski

and My sick pick is going to be a ThermoCell

Scott Tolinski

Patio Shield, which is a mosquito thing. So, typically, what you do concept of generics. And the way that generics Work in Rust is is really the exact same as they do in TypeScript. So if generics confuse you in TypeScript, they're gonna confuse you in Rust. They are the same, but it's really just a way of saying, and symbol? Yeah. I feel like that I feel like that's right. Right? I thought there were 6, but maybe there's not. I mean, there's more than that. Well, 5 I I said 7, didn't I? There's Symbol is the new one. Yeah. Cymbal's the one that people always

Wes Bos

there's a hack you can do to refill those.

Wes Bos

Like,

Wes Bos

the Halo Lock,

Scott Tolinski

So we've been hanging out outside a lot, and we got this little thermostat patio shield, which it's $18 for the thing.

Scott Tolinski

it's a battery free How does that how do I convert it to be assigned value down the road if I decide all of a sudden that I do want negative values?

Wes Bos

Rid. But then it also comes with these little, like, oh, I think I think I understand. So if you have a function that takes in, anywhere in the gym other than this just little sticky let's start off with variables

Scott Tolinski

Little cylinder that you turn and you put a little looks like one of those,

Wes Bos

it doesn't need to be. Yeah. Doesn't need to be something crazy fancy. Yeah. Although I did figure out, the flip the like, the benefit to that is that It's going to be fast as hell. Right? And you're sort of doing the work up upfront. Yeah. It is very wild.

Scott Tolinski

Magic Eraser sponges for, like, $14.

Scott Tolinski

And don't forget to subscribe in your podcast player All of my audio inputs that I have than in JavaScript. Right? In JavaScript, we just have number. Right? But here we have I 8, I 16, I 32, I 64, So you could think of it as like an array that

Wes Bos

a phone mount that I've been using in the gym. So a while ago, I sick picked

Wes Bos

magnetic

Scott Tolinski

Head on over to syntax.fm You're kinda stuck until you figure out exactly what it wants. Right? and seeing it being used more option in in in libraries and stuff. So, So just like TypeScript, you don't have to explicitly type everything all the time

Wes Bos

that, like, charger that does everything? a function is just another type. Right? Like, up to that max safe integer. Right? And that's like, what might be another example of

Wes Bos

Check it on out if you wanna learn a thing or two about JavaScript.

Scott Tolinski

rain every single day in an unbelievable may way and we got mosquitoes somehow. It's like Actual mosquitoes here.

Scott Tolinski

I I you turn this thing on, and I I don't see a single mosquito. You don't have to cover yourself in bug spray.

Wes Bos

And that's been working great in the car. But in the gym,

Wes Bos

rid There is,

Wes Bos

You have to douse yourself in deep every every night you go to the fire. I don't love that.

Scott Tolinski

So has to be a fixed structure that's determined when it's defined. Meaning, you cannot rid. Add or remove fields from a structure dynamically.

Wes Bos

Rid

Wes Bos

sick picks.

Scott Tolinski

Rid. But you end up having to buy little fuel cells and stuff. So, yeah, you think $18,

Scott Tolinski

So the pop socket for me The pop socket comes off. Yeah. It's just a magnet wallet, and then I I magnet on the thing. Yeah. But the next Step for me is there I think there's one that is like a well, it doesn't do charging through your wallet, so that would be a problem. So I'm gonna have to take it off no matter what either way. So I guess immutable. Sometimes there's what's called a a mutable reference, which we'll talk a little bit about that. But, And if you're converting it to another type of thing, you have to have some sort of rid. Conversion to another type of thing.

Scott Tolinski

but it ends up probably being a little bit We're closer to 30 or something after you you get it all all the little pieces for it. And what it is is

Wes Bos

3 M adhesive tape to it. So I was like, this is such a good option because rid. It doesn't I don't have to change my phone case. Yeah. I don't have to change the fact that it's MagSafe charging or any of that. I just have to

Wes Bos

rid And slap this little magnet thing on it and then be able to tilt it in any direction. And I haven't mounted anything that is a list of things

Wes Bos

It's true because it's Somebody those magic erasers, somebody just figured out that this, like, mildly abrasive,

Wes Bos

I'm I'm always like, somebody's probably figured out how to

Scott Tolinski

And I gotta say, and you select text and you are able to pull that text, you're just borrowing it from the main text. You're not able to change the main text. You're not able to change the new text. You're just borrowing it.

Wes Bos

So I found this thing called rid. Generics can be inferred at author time.

Wes Bos

this is

Wes Bos

That, you know, that spray and wash the podcast with the tastiest development treats. We've got part 2 to One of the most well received podcasts we've done in quite a while, and that is Rust for JS Devs. People

Wes Bos

rid. I also wanted something where I could sort of bring my phone around to the different parts of the gym

Wes Bos

kind of like the WyzeCam. It comes with these little discs.

Wes Bos

ESR Halo Lock for the car that, like, charges it and docks your phone.

Wes Bos

there's a bunch of YouTube videos where guys will rid. Use pliers to pull it off. It's the same thing with, like, the Swiffer.

Topic 4 23:37

String types

Scott Tolinski

And and we'll even talk a little bit more about that in a bit when I I have a section called what's up with at Or ampersand STR. So Okay. There's also an array type which is a fixed size Yeah. You're this needs to be a string slice, and you're like, oh, okay. I got it. This needs to be a string slice, and that can get you through some of those humps. Because rid. Really, the pain in learning Rust is when you hit a dead end, your code won't work, and you can stop at that dead end And you can choose to power through it or unlike in TypeScript where you can say, Your code won't compile it's unsigned, you get that much more. You get up to, like, what, 64,000 reference As to why that might be,

Wes Bos

rid Like like, let's do we have some more examples of what that might be? Like, let's say we had the transcript

Scott Tolinski

But an ampersand STR is a slice of a string. So you have an existing string. You take a slice of it. You're gonna be using it at STR. You need to take that string to borrow it to maybe grab a subset of that string, whatever. It's an ampersand s t r. That's what it is. Oh, and, It can actually convert is something that needs to be defined at compile time. So these are variables that aren't dynamically set.

Scott Tolinski

Yes.

Scott Tolinski

sequence of elements of the same type. Okay?

Wes Bos

from this podcast, which was,

Wes Bos

stick, like, the first 2 minutes into another string. Is that where I might use a if you're looping over 10,000,000 things. Like, I I tweeted out about reduce the other day, and a lot of people were like, use a 4 loop. It's much faster.

Scott Tolinski

And the ampersand oftentimes Struct is for, like, very structured data. Awesome. Yeah. So I think that we can leave it off there. Yeah. There's a lot of stuff. Yeah. A lot of variables and who knows what, but I hope you feel a little bit more confident getting into, especially, you know, like the signed and unsigned integer stuff, the string stuff. Those are the things that you use all the time. And if you think about the types of variables that we use inside of JavaScript, it's like objects, So if you're if you're looking at the thing like probably enough. Yeah. What do I need here? It's it ends up being pretty obvious This is basically for efficient memory usage. It's not having to create a new thing. It's just saying,

Wes Bos

rid Like, massive. Right? And I wanted to just show

Scott Tolinski

means that it's a reference.

Wes Bos

Slice string? Correct.

Scott Tolinski

There's a slice, a dynamically sized view into a contiguous sequence of events or events.

Topic 5 29:51

Memory overhead of hashmaps

Wes Bos

forgetting to actually use a map, and I just go for an object, but

Wes Bos

You don't have to, like, give a unique identifier to that div. You just literally use the div itself as the key.

Wes Bos

is really nice because it has has, But I guess the the benefit of that, I guess, is that it's rid That's why Rust is fast. Right? Because it's in JavaScript, It's it's wild. It's you look now that I, like when it got into it a little bit, I, like, start rid. Looking at every deck I see and every dock that I see, and I quickly realized that most people are just slapping

Wes Bos

have this, right?

Wes Bos

and we only ever had objects

Scott Tolinski

benefits by using a map? to 127, You know, we never have mosquitoes in Colorado. It's like I since moving here, I had seen, like, 5 mosquitoes total, But this year has been like monsoon crazy. We just been getting

Wes Bos

Even Ruby has a hash,

Wes Bos

working with a map Alright. That's it for today. Thanks, everybody, for tuning in. We will catch you later. Peace. Peace.

Scott Tolinski

Is that the same in Rust? Yeah. Hash map. The the types you can have for a hash map, you can use any of the numeric types. You can use the string types. You can use, enums

Scott Tolinski

rid. Maps are great, man. I almost never use a map. Do they give performance, smaller container sizes

Topic 6 43:33

Debugging &str issues

Scott Tolinski

It has a username that's a string. It has an email that's a string. It has a, I did. Yeah.

Wes Bos

ESLint on TypeScript ESLint. And then every time I hit something, I would go

Scott Tolinski

That could be a pain. So I I have a whole section here on mutable references, but since those are, like, really kind of a annoying concept, let's talk about a struct before we finish rid this off this episode, and we can handle immutable references on, like, a higher level episode. Okay? and there's no way around that. You know? Like, in TypeScript, you can just say, Hey.

Scott Tolinski

oh, let me just throw an any any on here or make TypeScript group happy and move along, whatever.

Scott Tolinski

are really good. So in the language tools, if you're just you know, you get the just like in TypeScript, you get the little red squiggly, and you get the same type of error. But if you're comparing it at the TypeScript rid. Errors, which can often feel like a giant tree of madness. Like, you're looking at the TypeScript error, and you say, oh, boy. I don't know about any of this stuff.

Scott Tolinski

chat g p t. I can you kinda gotta know what you're doing a little bit. But if you copy and paste the error with your code snippet and you say this code is giving me this error in the chat g b t, 9 times out of 10, it's going to say,

Scott Tolinski

Because immutable reference stuff is is really not that much fun, especially when you're first learning. So a struct It's going to feel familiar to those of you who work in JavaScript because it is really the closest thing to a JavaScript object

Scott Tolinski

Where you define a struct, and the way it works is you first define struct as a type. You say struct, the type name, an existing string or part of an existing string. Is that right? Yeah. That's my understanding of it. And this is one of those ones that you'll fight a little bit when you're first getting started because you're so used to just everything. Oh, I'll just make a new string or I'll pass this thing. It's Type of string or whatever. I'm not borrowing it. I'm not whatever.

Scott Tolinski

per brackets, and then you Say what's inside of the structure the structure.

Wes Bos

re Research it, and it says, alright. This is probably not a good idea because x, y, and z. Yeah. And you know what? The error messages in Rust

Topic 7 47:31

Adding methods to Rust structs

Scott Tolinski

If you wanna have a thing that you can add or remove fields from, that's when you use a HashMap. A HashMap Signed integers, And let's say you're getting rusty t, you know, your generic t something or owning something or borrowing something, whatever.

Wes Bos

your struct, your type. Rid And then to be able to add methods onto that type,

Wes Bos

struct or a a piece of data are Defined separately. Yeah.

Wes Bos

it's using the impl. So it's something separate that sort of comes after it. So It's kinda like the data

Wes Bos

and the logic

Scott Tolinski

You can't add or remove owning the the variable itself or borrowing it. We'll talk quite a bit more about that and how that relates to the type system, but it's basically one of these things you don't have to think about in JavaScript

Scott Tolinski

in JavaScript or beyond, you know, the fact that how you define methods? and have that type being used directly as the type itself. It's a generic type. Yeah.

Scott Tolinski

A struct in Rust I want to Temporarily borrow it like you see in a,

Scott Tolinski

Yeah. So it's interesting that you have to do it that way, but that's just that's just how you do it. So, Oh, so what are the difference between a struct and an object Well, you can actually do Rust air Tracking and performance monitoring with Sentry. So just like Sentry is awesome for all of the tools that we know and love inside of our JavaScripts and our, everything like that. It works well in so many other things, including, or something. 65,000.

Topic 8 27:09

Structs, enums and hashmaps

Scott Tolinski

which are Let's talk about this whole string slice business. Like, what's up with the

Scott Tolinski

is probably the closest thing to a JavaScript object. Rid. Right? It's a custom data type that groups together multiple fields of different types. You can have methods in there, although they They don't get defined into the struct as you do in in JavaScript, for a full archive of all of our shows.

Scott Tolinski

typically what you'd have. It's a a type that represents a value that can be One of several alternatives you could think of it, Enum, as being kind of like Does that make sense? What is this? And that's important because it means that because you're borrowing unsigned and signed integers, Strings and string slices more than anything, and enums and tuples and stuff. But, you know, the the ones that you use most frequently are are really Kind of the same. Awesome. Let's get into some

Topic 9 14:59

Generics in Rust

Wes Bos

rid meaning that like like a function can have an argument.

Scott Tolinski

Rust by this guy, Scott Talinski. It was

Scott Tolinski

So let's get into the actual types themselves. These are the things that are interesting in in JavaScript and TypeScript.

Wes Bos

sorry. I don't want to pump my own horse, but I always call them type arguments,

Wes Bos

Unreal. Unreal. Amazing.

Scott Tolinski

And there's also Something called zero cost abstractions, which because of the the way the types system works in Rust,

Scott Tolinski

to make abstractions if there are type issues, did they say contiguous that I downloaded directly, like an older like, a 2020

Wes Bos

You you don't you don't make your functions only do one thing. If you want them to be dynamic, Pass in the piece that needs to be dynamic. Right? Same thing with type arguments is if you don't know if it's going to be a string, a number, or a sandwich type, You pass that in when you go ahead and use that. I do love the, horn tooting. I I did once hear a really good podcast about we have array, a stylistic choice made by most Rust rid. Stations.

Scott Tolinski

Cost nothing.

Topic 10 37:57

Use cases for &str

Scott Tolinski

you know, I can play that video game, whatever,

Wes Bos

condition. Oh, I see. I see. That makes sense because, like, like, how how weight is transferred down to the ground. And It's crazy. Some some of these decks you see is just people are just bolt and stuff together

Scott Tolinski

memory allocation or copying. Okay? Again, performance based.

Wes Bos

That function would accept

Scott Tolinski

When do you use the at STR? breath strips. You put one of the breath rid. In there. Not a real breath strip, but one of the ones they give you. And it just keeps mosquitoes away for, you know, 12 hours or so.

Wes Bos

because you're passing in

Wes Bos

So, like,

Wes Bos

and that's the that you picked a while ago, the power wash, Dawn Powerwash? Yeah. Rid. Yep. I I said, oh, it's just, alcohol and Alcohol and Dawn Soap. It's not. It's it's so much better than that. Like, we've I've

Scott Tolinski

When you only need to read the string data,

Wes Bos

and you're You're passing in like a sentence and a word you're looking for.

Scott Tolinski

I can't. If I destroy it, you're going to be really angry with me. So I have to give that video game back in perfect enforced.

Wes Bos

rid. Ampersand strings

Scott Tolinski

When you need a string instead of a string slice is when you need ownership. If the string needs to be mutable or dynamically modified, math on x and and change it and whatever you need to do.

Wes Bos

Text in 2 different places.

Wes Bos

Rust is not making a brand new string every single time. Use ampersand string. It's just referencing the original one, and you're not copy pasting. You're not taking up memory,

Scott Tolinski

Hey. I'm I'm just temporarily holding on to this thing. And even and then I'm not holding on to it. I'm it's almost like I'm just, like, I'm just taking it for a second, and then you can have it back.

Scott Tolinski

And there there's definitely some caveats here because the way we're talking about this is right now as as as it is, like, Hey. We're just as a slice of a string. We're not changing, or we're not everything.

Wes Bos

I I guess, like so your initial string is always

Scott Tolinski

when you're working with borrowed data or string literals, And that's really just it. And so you're able to essentially this thing might be a string coming into this function. It might be a number coming in this function,

Scott Tolinski

When the string won't be modified ampersand item in ampersand.

Wes Bos

the person that copy pastes everything, you know, and now I have this

Topic 11 20:27

Signed integer ranges

Scott Tolinski

32,767.

Scott Tolinski

is, what, like, 2,000,000,000,000.

Scott Tolinski

So if you're getting into negative territories, Rid. The values don't change. Right? Then you also have a struct. Okay? Now struct I think that's that's how you do it in a lot of templating. I'm trying to think of, like, a, react way of doing it. But

Scott Tolinski

Sixteen bit Hey. I don't I don't necessarily, referencing

Scott Tolinski

to positive

Scott Tolinski

you're probably gonna be using an 8 bit or a 16 bit integer most of the time. And then if you need negatives, it's,

Scott Tolinski

signed. If

Scott Tolinski

the only time you ever need a 64 bit integer is if you're getting into Truly massive numbers considering a 32 bit integer We can pass in that type when we use it You also have a Vec,

Scott Tolinski

because

Scott Tolinski

So,

Scott Tolinski

to negative 127.

Scott Tolinski

Typically, you'll probably unless you're doing some really high number calculations, types

Topic 12 16:03

Basic types in JavaScript

Scott Tolinski

char, which is a unicode scalar value. You have Signed and unsigned integers. Now this is where it gets a little bit more interesting But I found it to be very effective at keeping Mosquitoes away, especially if we're, like, hanging out by the fire pit and just, like, you know, nobody wants to be swatting mosquitoes away while while you're hanging out in the fire pit making s'mores or something.

Scott Tolinski

rid.

Scott Tolinski

You have a,

Wes Bos

number, figure like, because it's just butane in there. Right? Like, that stuff's cheap. Rid. So you should be able to figure out that. I've looked into it because, like, we've got we get not so much right now, but at the beginning of summer, there's a lot of mosquitoes, and is that the key of the map can be an object. Rid. So if you you like, the key of of your map could be a div. And if you wanted to count how many times that div had been clicked, Or 0,

Wes Bos

null, Basically, it goes super high. And every time you make a number,

Topic 13 33:10

Signed vs unsigned integers

Scott Tolinski

So it can't do all type conversions. You can't do, You know, turn a number into a string or something

Wes Bos

what type of number you are passing in.

Scott Tolinski

just like it does inside of TypeScript, but it also does conversion of numeric types. It can convert numeric types. Yeah. It can convert enums, So in Rust,

Scott Tolinski

signed value.

Scott Tolinski

as it is to TypeScript. However, it can do one thing that the as keyword can't do in TypeScript.

Wes Bos

rid. A, is that something you might do or should you be as rigid as possible with your types? Like, maybe another example would be if you have

Wes Bos

And you say, alright. Pass me a number, but I don't care can reference something by its value.

Scott Tolinski

your value, rid. Weird ampersand before some types and things like that. So we're just gonna we're gonna take our previous episode, which we talked about mainly some, You know, high level differences between TypeScript I don't know. I'm I'm weird about that kind of stuff. So, yeah, I'll I'll take the, I'll take the thermostat. It works really well. Did you know, like, there's a lot of, like, little things like that where you can buy generic versions of fancy things. Obviously, you know this. But, like, I found recently you can get Mhmm. A pack of 50 as many as many things as you want in a struct. It is very object Like inside of JavaScript.

Scott Tolinski

and the as Keyword is really similar in Rust 8 bit is 127 1 is equal to, and then you say the user this is actually where it differs a little bit because you have to use that type here. You'd say is equal to Mhmm. And then you have the type name and then brackets.

Scott Tolinski

So it does typecasting almost like switch statement type control flows to be able to easily pattern match And then you want to have a mutable reference of it. You can use this fancy keyword at m u of the value So if you have an unsigned variable and you want That variable to now become a signed variable. You don't use a method or a function or anything like that. You use as.

Wes Bos

Or is there like

Scott Tolinski

You get to use the as keyword. So just like in TypeScript, we have the as keyword

Scott Tolinski

Well,

Scott Tolinski

You would say you would know when you're calling that function what the type of integer you're working with is. Oh, yeah. Right. Oh, you could infer it as well. Yeah. Oh.

Scott Tolinski

and it will both do type Casting just like it does in TypeScript, but it actually will convert it to be a signed because you can infer types Automatically. Yeah. The type inference to all of a sudden, in some cases.

Scott Tolinski

and char types.

Scott Tolinski

So you could say

Wes Bos

rid.

Wes Bos

Is there, like, a generic any number

Scott Tolinski

and I would like it to be a

Scott Tolinski

with

Scott Tolinski

is now as an I It works better, I think, than, like, a citronella candle or something like that.

Topic 14 09:16

Type inference in Rust

Wes Bos

JavaScript is when I upper case my

Wes Bos

And go in. I always use uppercase for that. And is that something that has to be done in Rust, or is that just a, You know, like, the Swiffer has that, like So you've heard of this thermostat thing? Oh, yeah. Yeah. Yeah. I've every time I see something like this, I'm like, rid. Someone's gotta figure out how to because, like, anytime I see, like, a product that's, like, cheap, but then they, like, screw you on, like, the refills, and they try to, like, set you up with the, We'll mail you 1 every month.

Wes Bos

They're generally like that. They are defined

Wes Bos

This Generally something I do in

Scott Tolinski

Yes. It is not required. It is a convention. So And and and in those aspects, it does feel a lot like TypeScript. Ripped. You know? And that's one of the benefits to working in Rust is that while it it feels like TypeScript on hard mode is really what it feels It still feels like TypeScript in a way that many other things don't.

Wes Bos

They're never going to change,

Wes Bos

const variables,

Scott Tolinski

And it's a convention that I follow in in TypeScript as well, and some people don't. Some people do. I pretty much just use it for true Constants like this. Right? Things that are are defined once.

Wes Bos

before I I make a fetch request or rid. Const per page is going to be I guess, per page might change depending on the user. But if it's something that is just a value that I set at the top of my file it doesn't work. Yeah. It doesn't work. Yeah. Like, you can't rid. Store an array of strings in MySQL.

Wes Bos

and they're not dynamic. They're not an output from a value. So That might be something like a const base name, and that's like the base of a URL like, a search term

Scott Tolinski

the all caps underscore naming of things for constants strings

Scott Tolinski

Yeah. No. It is, that's actually what they call themselves in case you were wondering. They are rustations. Rid

Topic 15 08:33

Const variables in Rust

Scott Tolinski

Const, however, It's often immutable.

Scott Tolinski

So these are actual true constants, so to say. These things are set to be a single value, not the return of a function or anything that's that dynamically. Oh, okay. So, like, the the output Ampersand string or ampersand mute, A it's a borrowed Contiguous?

Scott Tolinski

of and not a string of get name. Correct? Absolutely correct. Yeah. If you and and that's really the difference between let and const considering they're both Immutable by default.

Scott Tolinski

So you're not setting this as the result of a function. You're setting this to a single value. Right? STR type.

Wes Bos

of sorry. A a const must be explicitly set to a string

Topic 16 00:53

Audio interface issues in Chromium

Scott Tolinski

Like, for their interface has stopped showing up on all Chromium based browsers.

Scott Tolinski

for all you We have.

Scott Tolinski

No no Chromium based rather. So If you're out there and this this type of bug has

Scott Tolinski

So The type system in Rust, it will, yell at you. It will tell you a little bit of what you need to do to figure things out. It's one of those things that Especially when you're coming from JavaScript world, it can feel like you don't know what's going on at first, but it's It's also one of those things that the more you you work with it, the the easier and easier it becomes and the more you understand. So we'll definitely talk quite bit more about ownership because that's a big concept in in Rust.

Scott Tolinski

version of So well, okay. I I'm sorry. That is in a signed.

Scott Tolinski

We have. I have. Sorry.

Scott Tolinski

have, you know, it's like some of the default ones work just fine, but anything that's related to my audio interface does not show up In Chrome and all Chromium based browsers, including an older

Scott Tolinski

So, Likewise, the type system allows for complex pattern matching.

Wes Bos

that's the one you you have a u UAD device, so It's interesting that mine is not working. It's very it's definitely something like system level. You know? Like, we've we've sort of pinpointed it to it's not the website. It's not rid Just it's all Chromium based browsers. And, like, the only time I ever have issues with interfaces not showing up is when I have running Zoom. Rid. And Zoom does something to jack the interfaces and lock them.

Scott Tolinski

So for me, borrow essentially this data forget. Okay. So the types inside of Rust are very similar. You have a bool, which is a boolean.

Scott Tolinski

it's for all you web heads out there, this is Like a a really interesting bug. And and actually, West, just like moments ago, I found somebody on Reddit with the exact same bug with a different audio interface.

Scott Tolinski

resonated with you and you have some insight here, hit us up because I'm I'm trying to figure this one out. All of a sudden, it doesn't work. This person was having a a same issue with a a UAD Apollo interface.

Scott Tolinski

version of Chromium.

Scott Tolinski

they did not find any solutions, unfortunately. But

Topic 17 07:08

Using the as keyword for type conversions

Scott Tolinski

let x equals 5.

Wes Bos

and you set it to something like rid Like a number, you can never change that. But if you were to set it to an object or an array,

Scott Tolinski

Let x equals 5. That means that x is going to be always equal to 5. It is immutable. It cannot be changed.

Scott Tolinski

const that's, like, kind of just more of a suggestion.

Wes Bos

modified. So if you do ever want to, like, totally freeze it up, you use

Wes Bos

it's never going to change that object or array. But the values inside of those objects array can be

Scott Tolinski

all variables

Scott Tolinski

There is also, however, const. So you do have let and const, Our good old friends from JavaScript.

Scott Tolinski

and you typically assign them with let.

Scott Tolinski

So,

Wes Bos

to to do that. Totally.

Wes Bos

Rid. Yeah. It's like JavaScript const is by reference, meaning that when you create a variable

Wes Bos

The freeze API in JavaScript

Topic 18 25:07

Arrays, tuples and vectors

Wes Bos

or, like, the good state? Yeah. Yeah. Hook is a tuple because, like, it always returns to you.

Wes Bos

A specific type. Yeah. So, yeah, that is, like, a really good example of a 2 pole. Yes. It is.

Wes Bos

2 bold concept that we've kind of seen around, there's a proposal to add 2ples to JavaScript in the same sort of way. Yeah. That's one of those, like, rid. Gary wants in JavaScript where you hear the word, you know, like, oh my gosh. What the heck is a tuple?

Wes Bos

a name, and a is cool, That would be a number, a string, and a bullion. And, you know, you know ahead of time that those items are going to be in the ray and, you know, the types of them. Yeah. And it's kind of like, I mean, rid It doesn't,

Wes Bos

rid where you know how many items are in the array and you know the type of each of those items. So

Scott Tolinski

There's also something called an option, which Represents an optional value that could be some value or none.

Wes Bos

if you have like like, A spreadsheet is probably the most common example. If you have an array a a row in a spreadsheet

Scott Tolinski

Rid. So

Scott Tolinski

hooks, don't they return a tuple oftentimes or drop a review if you like this show.

Wes Bos

But at the end of the day, it's just an array

Wes Bos

accepts for But

Scott Tolinski

There's a result which is the result of an operation, and result rid. Is one of the cooler ones because, number as well.

Topic 19 06:11

Signed and unsigned integer types

Scott Tolinski

has cargo to do Absolutely everything for you. So this episode will be a little bit more more code based, but we're gonna be talking about the type system and variables and those types of things.

Scott Tolinski

and Rust and, basically, how Rust

Topic 20 19:04

Unsigned integer range

Scott Tolinski

Yes. Here's why that exists. So we have signed and unsigned in. It's so funny. Every time I see the word signed, I always think about, like, a certificate. Right? Like, this is Like a SSL certificate or something. But that's not what this is. This is a like, you could think of it as a straight up number sign. Is it a plus or a minus? Right?

Scott Tolinski

wherein This allows us to do things like really advanced, and some of, like, the weirder things you you see in in Rust occasionally that might make you confused, like the, or not guess, but know what your type is based on its usage.

Scott Tolinski

includes negative numbers as in it can have a negative sign in front of it. So that's why the range is smaller because the range is negative 127

Wes Bos

why and what is that for? not straight up strings but

Scott Tolinski

So a group of a generic, not like a generic any number there's this concept of ownership and borrowing, which does Come into play in types a little bit where you are going to be,

Scott Tolinski

So a signed integer

Scott Tolinski

Where an unsigned integer will go from 0 to 255.

Scott Tolinski

It is 127.

Wes Bos

Rid. Yeah.

Scott Tolinski

0 is the lowest you can go. Oh,

Scott Tolinski

signed integer could go from negative 127

Wes Bos

that makes so much sense. So half of it is used for the sign. Half of it is used for the sign.

Wes Bos

Why does that exist?

Scott Tolinski

Signed means there's no concept of negative, and it's just by default, but rid. You should you should be doing this since it's like

Topic 21 42:35

for loops with &str

Scott Tolinski

because this is where it really gets Oh, man. It gets annoying.

Scott Tolinski

Wait a second. Maybe I don't I don't got this stuff The length of your integer, you could think of it as like really small numbers just need an 8 bit integer. Larger numbers need a larger bit integer, it works in Firefox. It worked in Safari.

Scott Tolinski

where if you have an ampersand

Scott Tolinski

try to save your bacon here, essentially. Yeah. I was are immutable,

Topic 22 03:21

Const variables in Rust

Wes Bos

lumber together, which in JavaScript. And now that we have maps, I find myself often

Wes Bos

rid. Sometimes fine for, like, like, ground decks, but, like, the high ones, you don't want to mess with it. You have to, like, understand, String,

Scott Tolinski

syntax is presented by rid. [email protected].

Wes Bos

is Is there,

Scott Tolinski

Deck building, but you can have STR is what's called a slice of a string.

Scott Tolinski

a couple of decks. He's like, Each Those are the type of micro optimizations and hoping for the best. Totally. Yeah. My dad was an engineer, so his And this is, like, legit immutable. It's not like JavaScript's Struct name. So emple user then brackets.

Scott Tolinski

rid. Maybe even built, like, 3 decks or something. He he built my all of my family's decks, which are auction actually, like, really Intense decks. So when we we had our house in Michigan, what we're gonna do is we're gonna just see how far we can get each episode, and And we're gonna chop it off at that point and pick it up because I could just keep going on this stuff. Yeah. We'll make a playlist for for all these as well. The new site, as well as a Spotify playlist

Scott Tolinski

and he designed our deck, and then we built it together. And then And it's a type of thing that gets annoying when you're writing the code. Because if you don't know why you're writing and what you're writing, you can almost feel like you're just, like, tossing in ampersands and, But you might have been asking yourself, hey, I have eight instead you're working with 4 items here. It's not gonna make a difference.

Scott Tolinski

I I built, 1 deck with my dad. My dad has designed because a signed integer my Unsigned variable

Wes Bos

all the summer. And I'm working on a deck right now, which is kind of fun. I've never built a deck before, so it's flexing my carpentry skills. Yeah. I've built, 9

Scott Tolinski

it's an intense process, but it's super rewarding. Yeah.

Topic 23 40:24

When to use &str vs str

Scott Tolinski

So, Returns an immutable reference to the type of tea.

Scott Tolinski

4 or when you want to avoid unnecessary is just a convention.

Scott Tolinski

which is as let mute value is equal to 42. Right? You're just setting a mutable variable to the number of 42.

Scott Tolinski

kind of is almost always used in this way where you're taking a borrowing of something. Right? So

Scott Tolinski

rid. You can have a value, ampersand It can do c plus plus rid. Kotlin. No. Kotlin.

Scott Tolinski

for ampersand item in ampersand fact is basically Immutable can't be changed. If you want to define a mutable variable, one that is able to be changed, you have to explicitly state that it's mutable with the mut keyword. So you then say let mute x equals 5. Now x is is now mutable. You can do x,

Scott Tolinski

If you want to concatenate or manipulate strings with dynamic changes, you need a normal string type or you want to take Ownership of the borrowed data and modify it. You need the normal string type. Beautiful. So if it's being changed or whatever, it's an existing or non existing thing. You need the add string type. And this kind of the ampersand In in Rust, it typically it's it's way easier to read, and it it the English in it's pretty good in terms of, like, actually being able to understand it. But I've also found that if I'm Copying and pasting an error into, say,

Scott Tolinski

in in Rust, it's oftentimes Okay. So let's talk about, you know, one of the things we talked about was the signed and unsigned thing where we had our signed and unsigned. Yeah.

Scott Tolinski

the ampersand sign, when you see it being used

Scott Tolinski

thing has thing.

Scott Tolinski

And then that creates essentially a reference In practice using VEC their audio inputs, which is a dynamically sigh resizable heap allocated vector or array.

Scott Tolinski

I want to temporarily I asked him to help me, to a sequence of characters. You're It means it's often rid Or or custom types. You could define a type and have those be the the key of a hash map.

Scott Tolinski

that gets into, like, really more intense borrowing and really more intense referencing of stuff. You can also use it for pattern matching or looping. Right? You can say So if you are out there and you're thinking, oh, yeah. I got this Rust stuff. Right? The the moment you hit Yeah. The ampersand symbol and the whole mutable references part of all of this is the part where you start to feel like, values to it.

Scott Tolinski

So if you were doing, like,

Scott Tolinski

Immutable.

Scott Tolinski

It doesn't mean it's always

Topic 24 36:16

The as keyword

Scott Tolinski

You're always either, you're not using a larger container than the type of number you're ever going to be able to need. Right? You don't need a 64 bit Yeah. Integer if you're only going to be having 1 through 5. You know? Like like, people might be saying like, that's annoying. Like, I don't I don't Don't box me in. I don't know what my variable my integers are going to be. You kind of should.

Scott Tolinski

rid. Or you're borrowing a sequence of characters.

Scott Tolinski

essentially 127.

Wes Bos

rid Ampersand string.

Scott Tolinski

enough to fill the rest of this episode with. It it's that in in a big of a topic here is basically And this is the whole bit of signed verse unsigned, which we'll talk about

Scott Tolinski

in conjunction with the s t rid. Type to represent a string slice

Scott Tolinski

ampersand stuff? So the ampersand stuff, Which ends up getting to be probably For each of these so you can go and just listen to them all in one go. Yeah, buddy. Yeah. That's a good idea for the site. We have an added playlist. We should get we gotta do that. That's easy. Okay. Alright. Next up is, in Rust. How do they work? Yeah. So So I think the general vibe of this entire episode is we're gonna be talking about the type system. We're gonna be talking about variables. We're gonna Talking about mutability and mutability to So, therefore, when I Oh, if I borrow if I borrow a video game for you and then I,

Wes Bos

Does that make sense? Yeah. I think so. I'm just rid. I'm trying to understand, like

Scott Tolinski

borrowing You just toss that bad boy as a parameter in your object.

Scott Tolinski

or what's a reference to another existing string.

Wes Bos

why you would want

Scott Tolinski

So in Rust,

Topic 25 31:19

Benefits of Map in JavaScript

Wes Bos

like doing stock market rid. Nanoseconds.

Wes Bos

Serving or anything that needs to be lightning quag. Yeah. And if you're doing if you're literally doing something that is so big, Rid. And the first thing is going to be a specific type of your state, and the second thing is going to be a function that,

Wes Bos

If I wanna get all the shows where Scott started it, I would just say shows dot get and pass in Scott. Yeah. According to this, it does say that they do have higher memory overhead and slightly slower performance. But I I I think in the right situations, that's the rid The ticket. Yeah. I guess it depend depends on what you're doing. Right? Like, if it's

Wes Bos

Yeah. I'm looking over 3 things, your brother. Like, it doesn't

Wes Bos

let's say we had

Scott Tolinski

that drive me nuts. As a YouTuber, the amount of times that people would be like, rid. Benefit. Again again, it's a little bit harder, but you get the major memory and and performance improvements because of it. Alright. I think I understand that now. It's an interesting thing. And, again, not something we ever have to think about too much. But, again, it's here for memory usage. Right? We don't have to create something new. You're just borrowing it. So

Wes Bos

sort

Wes Bos

So again,

Wes Bos

the podcast by who started them rid And you by user. Right? Instead of just using, like, a user ID as the key, you could literally use the user object or the user type as the key in the map. Rid. And then you can say, alright.

Wes Bos

like, if you wanted to use an object, You know, there's, like, hello world in every language. It's not a bad thing to look at

Wes Bos

Then maybe you need to

Topic 26 10:47

Statically typed and strongly typed

Scott Tolinski

Feels very familiar. It's very TypeScript as compared to other type systems.

Scott Tolinski

In Rust, however, Rust Rust's type system, if you're coming from the TypeScript world,

Scott Tolinski

basically are the way that you say what things are. You know? This is a string. This is a a number. Whatever.

Topic 27 12:19

Type inference in Rust

Scott Tolinski

And Type inference is the ability for the type system to guess Dynamic key value pair.

Wes Bos

And I literally typed one thing and the rest of it was just inferred.

Wes Bos

is super powerful in in all languages. I was looking at some code I wrote this morning, And it was probably 20 lines of a fetch.

Scott Tolinski

ever is memory management.

Scott Tolinski

Also,

Wes Bos

Rid and that's that's really nice to have because you don't have to go. Like, that's the sort of the downside people think to TypeScript a lot of times. They're like, oh, I don't feel like having to add all this rid of stuff to it.

Scott Tolinski

And especially if your libraries are beautifully typed, a lot of it is just inferred. Yeah. Totally. So it it basically like you say, it allows for Nicely readable and concise code without, you know, sacrificing your types.

Topic 28 00:13

Rust for JS Devs Part 2

Wes Bos

the as keyword, you name it. Hello, Scott. How are you doing today? Oh, I'm doing Hey, man. We've been, having so many audio difficulties.

Scott Tolinski

I it's the this is And then the value.

Wes Bos

and explained what they are in relation to a JavaScript developer who knows what those things are. Rid. Now what we're gonna do is to dive into

Wes Bos

really liked, rid. Scott kinda went through some of the very basics of Rust Rid. We're doing 99 bottles of beer on the wall here, you know, like

Wes Bos

part 2, which is a little bit more of the types and integers and Different types of numbers, strings, Oh, I thought it was 255.

Topic 29 24:50

Slice references with &str

Scott Tolinski

Yeah.

Wes Bos

Next to each other or connecting.

Scott Tolinski

Yep. That's nice. There's a a tuple, which is a fixed size ordered collection of elements possibly of different types.

Wes Bos

Contiguous sharing a common border. Touching. Touching.

Topic 30 02:18

Let keyword for immutable variables

Wes Bos

And specifically, Undefined,

Topic 31 23:08

Floating point types

Scott Tolinski

And that's a capital s string. K. So you'll you'll see string as the basic definition of a string everywhere in your code. However, There's also this weird

Scott Tolinski

And, being used to take That means you're not able to mutate that sequence because you're just borrowing it. You can't change it. You're just borrowing it. You're saying, So I found this to be actually very effective,

Scott Tolinski

sized strings So you have to know what the structure of the object is.

Scott Tolinski

We also have strings which are dynamically say, like, should this be this be done at a database level? You know? Yeah. Where could this be done? That, Yeah. That is not where I'm doing it in just straight JavaScript.

Topic 32 11:11

Compile-time type checking

Scott Tolinski

and JavaScript in general, it is,

Scott Tolinski

statically typed and strongly typed. So and for those of you who are like, well, now I gotta worry about all these different ones, Well, think about it like this. I I would say most of the time, the numbers that you're using are going to fall into Okay. You can also do it for ownership transfer or function returns, So you you are you are correct.

Scott Tolinski

How about we just compile anyways right now even though the types aren't passing? Yeah.

Scott Tolinski

Unlike TypeScript is negative And just like TypeScript, there's also type inference.

Scott Tolinski

And just like TypeScript, the main reason is It reduces the potential of runtime errors. It doesn't eliminate runtime errors, but it reduces the potential of runtime errors.

Scott Tolinski

But an object that has very explicit value

Topic 33 46:02

Defining structs in Rust

Scott Tolinski

And then in JavaScript,

Scott Tolinski

Now here comes the fun part. If we wanted to have methods or there's compile time optimizations So Yeah. I am very confused temporarily borrowing this value to loop over it.

Scott Tolinski

just like you would a normal method. So a Because Chromium

Wes Bos

values.

Scott Tolinski

But in Rust, you use this imp imple keyword where, like, implement. Rid. Yeah. Simple.

Wes Bos

types, there is a max integer, And that rid What are the keys of a HashMap? What can the keys be? They can be anything? Can they be any type? Or can they just be strings? Because that's one of the nice things about a map in JavaScript rid Wondering, I looked it up quickly, is, like, is there a tool that will tell you when you're possibly doing something you shouldn't be doing? Rid and maybe we'll have a whole show on on Rust tooling, but it looks like there's this thing called Rust Clippy, which will sort of yell at you. And That's one thing I really liked when I was learning TypeScript is I had a very aggressive,

Scott Tolinski

is active, and that's a Boolean. Right? fields from it.

Scott Tolinski

And then you write a function, f n login, and then you have just like a normal function. From there, you can then use,

Scott Tolinski

Yeah. And so after you have defined your struct, you the this gets into the lovely world of borrowing, but you could think of the, float,

Scott Tolinski

And then from there, you could put the values in just like you normally Would.

Scott Tolinski

is you create the object. Right? And it's you create the object instance. And in Rust, you do that the same way you would By putting something into a variable, let user one of the,

Scott Tolinski

you know, user.one.login His whole thing was better to over engineer it than to under engineer it, and, they were always, like, super sturdy. So I was trying to think of, like, a really good Metaphor for this. And I was trying to think of, like, oh, you when you do, like, a screenshot a group of characters from another string.

Wes Bos

In in TypeScript defining are With Rust, you define

Scott Tolinski

methods inside of this object. In JavaScript, Granted all the permissions, like, you could try everything. So I'm, like, 1 step away from reformatting my computer over this, which rid. Obviously, it would be awful, awful process. Well, Wes, how are you doing today? I'm doing pretty good. Just up at the cottage, and same with u 8, u 16. And and these things are basically like, a front end template. Right?

Topic 34 04:41

Debugging Rust apps with Sentry

Scott Tolinski

Unity if you're doing game dev or Unreal Engine if you're doing game dev. But it it can debug serverless. It can debug I have been having so many audio issues, and

Scott Tolinski

You can do so much with this tool. You can dive in and find out exactly what's going wrong, especially if you're just learning Rust. You're bound rid have some errors and mistakes, so check it out at century.i0.

Scott Tolinski

Ruby, Pearl, Python, PHP.

Scott Tolinski

Use the coupon code at tasty treat, all lowercase and all one word, and you will get 2 months for rid. Free. Alright. Let's get Rusty. Alright. Let's get on into So, yeah, it it's not required to be that way, but that's Typically, how you see it being written in the real world. So let's get into the type system. So, you know, we have types in TypeScript.

Scott Tolinski

Oh, yeah. It can do everything. Honestly, it's not a bad like,

Scott Tolinski

There's Cocoa. You can do any of the Apple stuff. Right? You're doing the macOS. What what are you gonna do? Like, a Vision OS app? Maybe you're gonna put 10th century on that bad boy. And that way, you can track error's performance.

Scott Tolinski

and you need to debug your Rust apps.

Wes Bos

Rust for JS devs part 2. If you haven't listened to the first one, rid. Maybe a good idea to go give a quick listen to that, but rid. And you

Wes Bos

how to set up Sentry in every language because it gives you a nice little end product. In every language. It's yeah. It's kind of it's kind of a nice little hello world. Yeah. It's the same thing in every language. It's beautiful.

Topic 35 21:33

Choosing integer sizes

Wes Bos

rid Annoying to us as JavaScript developers, but Oh, okay. I just I just asked chat gpt,

Wes Bos

and I Wes and Scott will be 2 different Scott and me, and we were users. Right? And you wanted to, of a

Wes Bos

entries in a totally different table, and you end up with so many tables. But boolean,

Wes Bos

rid The Syntax site, we are building with Prisma,

Scott Tolinski

So it ends up being pretty obvious when you're writing your code. It just seems like a lot to know ahead of time when you're thinking about it coming from TypeScript.

Wes Bos

store an array of strings,

Wes Bos

and we're using the MySQL adapter. Right? Yes. Rid And if you wanna do something as simple as

Wes Bos

rid. I'm sitting there being like, this is such a pain in the butt. Oh, yeah. If I just want a store, Wes comma Scott,

Wes Bos

You have to create another table

Wes Bos

if you can give it a little bit more foresight, you do get those perf wins. Like, I had the same issue with the Boy, do I have a sick pick for you today.

Scott Tolinski

A a u eight, right, because there's no negative values.

Scott Tolinski

Now there's also floating point numbers. There's f 32, a 32 bit floating point, and an f 64, 64 bit floating point. Those are floats Just like in JavaScript, you are decimal based things.

Scott Tolinski

There's less than a 100 and or 250, 255, whatever.

Wes Bos

for those things and have a relationship. And

Topic 36 02:44

Mut keyword for mutable variables

Wes Bos

enjoying And I love I love stuff like that where somebody figures out, I don't I don't know if it's performance benefits, but the API described or and be able to mount it.

Wes Bos

Google Hangouts does a good job at

Scott Tolinski

New profile, rid 32,767 If you're out there and you still haven't used TypeScript,

Topic 37 17:09

Signed vs unsigned integers

Wes Bos

max_safe

Wes Bos

quadrillion.

Scott Tolinski

define the size of the container of the number

Wes Bos

Let me see.

Wes Bos

underscore integer.

Wes Bos

how many characters long is that? phone mount holder. So what it is rid Is it obviously magnets to the back of your phone, and and it has a like a ball bearing swivel on it so you can spin it in any direction. But the other side of it has rid a magnet on it. So you can stick it anywhere that is magnetic. Right? So if you have a rack in your gym, You can stick it anywhere on the rack, which I find really helpful if you're trying to, like, watch a video and figure out form and all that.

Wes Bos

Sixteen characters long. That makes sense. Right? So yeah. It's like That's cool. A lot of this seems

Wes Bos

capital n number dot max Sick. Jim's plugs, rid. Westboss.com/courses.

Wes Bos

and it is. You can find it out if you go into your dev tools and say,

Scott Tolinski

In the type, so that way I get bitten more than anybody I know, Or to borrow without taking on our ship.

Topic 38 18:15

Integer sizes and performance

Scott Tolinski

0 But, again, yeah, it's one of those things that we take for granted. And especially when you first get into this, you're like, that's annoying. But it makes so much sense. And, ultimately, when you're writing your code, You do know, hey. This thing I'm I'm tracking days days of the year here. It's it's obviously going to be So this It's basically a system that says all types are checked at compile time.

Wes Bos

JavaScript is allocating the memory for you to possibly count

Scott Tolinski

like an 8 bit integer Oh, nice. Rustations. He namedroppin'.

Scott Tolinski

is basically anywhere from Goes from a negative to a positive.

Wes Bos

unnecessary in a lot of cases. So By sort of knowing ahead of time, you get a lot of performance benefits. Right? Absolutely correct. And object, rid It it inputs and outputs

Scott Tolinski

where you have, to 127, You know? indicates that a function

Wes Bos

I'm gonna count from 1 to 2.

Topic 39 13:38

Memory management in Rust

Scott Tolinski

And here, because we don't have a garbage collector, you do have to worry about and think about memory management. And,

Topic 40 26:22

Option and Result types

Scott Tolinski

later on in this series. I have a so many notes for this stuff that, Just that const needs to be essentially like a true constant. Uppercase.

Scott Tolinski

it it allows the control flow to be really nice because the result can either be o okay or error. And if it's okay, it it allows us for really easy error checking. And if you come from the world of JavaScript using async await and checking, rid. Error exhaustive states with catch and all that stuff.

Wes Bos

And the next show we're recording after this, I'm going to talk about it, how to use it with Fetch. Nice. Yeah. That's awesome. And, we'll even have an example. Rid. Talk more about air handling,

Topic 41 35:25

Type inference with generics

Wes Bos

rid. How do I make I, like, ask her for a function. It's like, here's I thirty two. But I was like, well, what if I don't know if it's an I thirty two? And then it says, use a generic. And it shows an example of passing it. And that's good because, like, But Yeah. I'm not like a a pro Rust app or something. Do you know the length of your array ahead of time? Right. I find myself The whole result business is gonna feel like a dream to you. Sorry. I'll rid I'll just say I just wrote some notes this morning on how to do that in JavaScript, because I just recorded a video for my TypeScript course.

Scott Tolinski

Okay. So Yeah. That's the as keyword.

Wes Bos

one thing I think a lot of people don't know in TypeScript land is that

Wes Bos

you don't have to rid. Say, alright. Well, I'm passing it to I 32, so now I have to type I 32.

Wes Bos

by the type being passed in, and Beautiful. Yeah. It's it's funny because, like, most Languages

Wes Bos

That can be inferred. Yeah. Totally.

Topic 42 00:00

Transcript

Announcer

You're listening to Syntax, the podcast with the tastiest web development treats out there. Strap yourself in and get ready. Here is Scott Talinski and Wes Boss. Welcome to Syntax,

Topic 43 48:36

HashMap for dynamic structures

Scott Tolinski

strings, numbers, booleans, arrays.

Scott Tolinski

You know, it's it's no different except in Rust. You end up using Vect. You end up using struct, an unsigned value And I was surprised because when you look at it, you're like, I don't know if this thing's gonna work. Might as well just try it for $20, whatever.

Topic 44 15:53

Zero-cost abstractions

Scott Tolinski

You know what types of types we have, Wes. Can you name the types in JavaScript? Ampersand s t r, as we mentioned, is a string slice. The ampersand symbol is used that can be changed.

Share

Empowering developers for over 286196614490 milliseconds!