Enums and Pattern Matching in Rust

preview_player
Показать описание
The ultimate Rust lang tutorial. Follow along as we go through the Rust lang book chapter by chapter.

0:00 Intro
0:41 Defining Enums
1:48 Enums in Structs
2:37 Values Inside Enums
3:54 Enum Methods
4:16 The Option Enum
6:56 Using Match Expressions
11:01 Using if let Syntax
12:04 Outro

#letsgetrusty​ #rust​lang #tutorial
Рекомендации по теме
Комментарии
Автор

go developer here. Had to comment when I heard your little intro. Gotta say I'm loving rust. Already subscribed. Thanks for the awesome tutorial.

richbaird
Автор

Dude, I think your channel is amazing, I can't believe people still deal with the same memory errors on C and C++, it's time to switch to an actual modern language. And I'm glad that people like you are making this community one of the best among the programming languages.

BurningBlueFox
Автор

With every subscription you convert a Go dev. xD

joelmontesdeoca
Автор

Wow dude, been using a book to learn Rust and each chapter was just bloat of unnecessarily complicated examples. You explanation is just spot on! Please continue updating the playlist, even after The Rust Lang Book is done. Maybe a code-along with a webapp or a terminal utility.

dariuselijah
Автор

Rust's enum are so amazing! My c++ mind is blown.

NeytozINF
Автор

11:30
tested, it works, but is confusing, and I still don't know any case where you would specifically need that syntax, but this also works:
if Some(3) == some_value { /* do something */ }

ilyasssaadi
Автор

11:27 Couldn't you have used a normal if-statement in this case?
You can always compare against a specific value like _Some(3), _ the "if let" syntax only comes in handy when you want to catch any _Some(_)_ or want to reuse the inner value that you're comparing against, for example:

if let Some(value) = some_value {
println!("The value is {}", value);
}

feathecutie
Автор

This channel is amazing, you explained and digested such a complex language well, thank you

tadiwashangwa
Автор

Your "convert a go developer" comment is priceless. I do love go...but as I learn more rust, I see less of a need/desire to use it.

sunnymittal
Автор

I really like the way you explain concepts of Rust. I have been reading several books on Rust and enrolled for courses on the same but I find your explanations being concise and well delivered. I rate you videos on learning Rust at 9/10.

I have only two criticisms
1) Fast forwarding sections of the video where you type, I think it is okay for us to follow you type at natural speed as it takes time to absorb and process the information taught. I find myself having to pause or even rewind to better understand these sections.
2) The background music, I think background music in educational videos cause some distraction. The inclusion of background music seems to be a common trend on YouTube videos, but I would be had pressed to see a college class being taught as music plays in the background. The background music in your videos seems to oscillate in volume with a frequency of 1 Hertz.

From the comments, it seems I am the only one finding these two challenges. Probably this requires more investigation. Perhaps someone with training and experience in education and learning can provide their input on this matter.

openyard
Автор

It worked. I was a go developer, but I couldn't stand the garbage collection. So now I'm the rustacean!🙂

patrykszczerba
Автор

This was really helpful. Can't read the book rn. Nice to have a quick visual alternative

tech
Автор

Thank you for your hard work. Best Rust channel in my opinion. Keep it up!

youngming
Автор

For the if let syntax, it also reduces the amount of identantion used, e.g:

match some_val {
Some(val) => {
use(val);
},
_ => (),
}

if let Some(val) = some_val {
use(val);
}

DanielQRT
Автор

3:33 - That's not an anonymous struct, since there's no anonymous structs in Rust.
In the Rust Book it's described as "has named fields like a struct does" and in the example it's commented as "c-like structures".

howdy_official
Автор

I've seen syntax similar to 'if let' in other languages. It makes heaps more sense if you consider an example of a bound variable:

if let Some(x) = some_value { ... }

You're conditionally defining "let x" to be the bound value within the following code block if it matches the specified variant.

msmyrk
Автор

Really like your videos, thanks for making them.

voffknur
Автор

It's a relief to know the if let syntax is confusing for you too, I find it so confusing too, the readability is strange

alfredomenezes
Автор

if let is very useful (succinct) if you use it correctly.

if let Some(item) = vector.get(20) { // or any Option returned by a function
// do something with item
}

That's what if let is for.

thachnnguyen
Автор

Thanks for these videos they are great. The if let syntax looks familiar to c++ if init statements

UnknownIllusionist