Closures 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:29 What Are Closures?
0:50 Example Program
2:55 Refactoring With Functions
4:07 Refactoring Using Closures
6:31 Type Inference And Annotation
8:06 Generic Parameters And Fn Traits
15:33 Capturing the Environment with Closures
19:12 Outro

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

god damn this is a fucking gem. Im tired of reading and falling asleep. Thank my dude!

kid_kulafu_
Автор

did you choose the random number 7 with a fair dice roll?

RoamingAdhocrat
Автор

Thank you, as a Rust beginner, this one really helped me understanding how closure works.
You've build an awesome channel for anyone learning Rust !

Marcus_
Автор

finally learned closures, it seems to just be a function that captures its env and has extremely weird syntax

ladyViviaen
Автор

At about 15:00: IMHO, this technique is called "memoization" = storing results of expensive function calls in case of subsequent calls? Great to see that this can be quite easily be implemented in Rust (even if Haskell and the like have it built-in)

karstenmeinders
Автор

Your explanation that FnOnce, FnMut, and Fn are the same as calling to a regular function did the trick for me.

FnOnce is a closure trait for - fn foo(val: i32) { ... }

FnMut is a closure trait for - fn foo(val: &mut i32) { ... }

Fn is a closure trait for - fn foo(val: &i32) { ... }

UdiTalias
Автор

Excellent work! I'm closer to fully understanding closures, but another video on them with more examples would be great!

tino
Автор

Thank you Bogdan, the videos that accompanies the book's examples are really usefull. I am new with Rust and your videos make the langage very approachable for a beginner like me.

thanhliemtran
Автор

Hey 👋🏻 great Video! I would love to see more about closures. Especially more complicated things with structs

LiiittleBigPlanet
Автор

I thought that the pipes were a capture block, and the full closure definition was |captured_values|(arguments) -> return_type { code }. Thanks for the clarification

maksymiliank
Автор

Love your videos! This one was fantastic. I've used closures in other languages a lot so this was great for a way to see how Rust does it.

jmsdnns
Автор

This explanation helped me understand closures a lot better after reading about it in the book. Nice video!

Zombehmoviez
Автор

Great work, Bogdan! The videos are an awesome complement to the Rust book- I am watching your videos after reading the chapters, to gain extra understanding.
Would love to see more videos on closures or any other subject. Your work is excellent, keep it up! ♥

mariavarvaroi
Автор

man really enjoyed your explanation
it almost make me want to learn rust...

samansamani
Автор

This was such a beautiful example!
I'm liking rust!
Thanks!

SauvikRoy
Автор

Yo bro... This playlist is just too awesome. Thanks a lotttt

shubhrantyadav
Автор

Really, all this rigamarole can be implemented in C or C++ by simply declaring your generator function with a static result member... and then tag it with a bool if it's been generated or not. Then you can call the generator to your heart's content and it will either generate the result (the first time) or return that result (every subsequent I'm not a Rust programmer, I am still learning, but I have watched 10-20 videos so far and I have yet to find a feature of Rust that you can't do in C++ if you choose to use the specific feature as it is implemented in C++. I am sure I will find something eventually that will prove this maxim wrong, not yet.

activelow
Автор

You really explain very well. Thank you!

froggyana
Автор

Hi there, i have a question. at 10:59 on line 40, v is declared and set equal to (self.calculation)(arg) where(self.calculation) is the closure and (arg) is the parameter. I understand what's happening but I'm having trouble with the syntax. I understand why (arg) is in parenthesis since this is the syntax for passing an argument to a closure, but why is self.calculation in parenthesis?

seenlenz
Автор

I unironically love how you pronounce "шtruct". I am going to annoy so many people copying this

Kord