No video

Iterators in Rust

  Рет қаралды 49,807

Let's Get Rusty

Let's Get Rusty

Күн бұрын

The ultimate Rust lang tutorial. Follow along as we go through the Rust lang book chapter by chapter.
📝Get the FREE Rust Cheatsheet: letsgetrusty.com/cheatsheet
The Rust book: doc.rust-lang.org/stable/book/​​
Chapters:
0:00​ Intro
0:33 Processing Items with Iterators
2:32 Iterator Trait and the next Method
4:39 Methods that Consume the Iterator
5:31 Methods that Produce Other Iterators
6:24 Closures that Capture Their Environment
8:42 Creating Our Own Iterators
12:48 Outro
#letsgetrusty​​ #rust​lang​ #tutorial

Пікірлер: 53
@letsgetrusty
@letsgetrusty 3 жыл бұрын
📝 Get your *FREE Rust cheat sheet* : www.letsgetrusty.com/cheatsheet
@ionprimus5322
@ionprimus5322 3 жыл бұрын
I'm really enjoying these videos. I'm glad I've chosen Rust as my second language.
@edboss36
@edboss36 3 жыл бұрын
What was your first?
@ionprimus5322
@ionprimus5322 3 жыл бұрын
@@edboss36 Python. The simplicity of the language made it difficult to pickup Rust's syntax and borrow checker; but right now I'm really enjoying it.
@edboss36
@edboss36 3 жыл бұрын
@@ionprimus5322 I’m a beginner at python, most things I still have to search up but I want to master python and also learn C
@ionprimus5322
@ionprimus5322 3 жыл бұрын
@@edboss36 That's great to hear! My advice is that you stick to one language and learn it well before you start learning another.
@davocarli
@davocarli 2 жыл бұрын
I'm also really glad to be learning Rust as my second language I want to get "really good" at. I'm self-taught and consider myself very proficient in python. I also know some javascript & java, but spend a lot of time googling when I'm writing in those languages. I want Rust to be my second language that I can write confidently (which I realize will take TIME). I think it's a good compliment to python in that it has very different focuses and is great for writing the performant code that python is incapable of.
@risto7566
@risto7566 2 жыл бұрын
Hey Rusty, checking out your vids every time I come across something while working on a project with barely any rust knowledge. Good tutorials for devs, thanks for that!
@PauloAlexofAnjos
@PauloAlexofAnjos 2 жыл бұрын
Great channel! I've just dicovered you by this video, but soon will be watching the entire series. Thanks for sharing your knowledge with us
@meditating010
@meditating010 2 жыл бұрын
i really appreciate your stuff, you get straight into code and your description gets me into mood for doing more rust. Coming from 15 years of JVM languages, ECMAScript and Go, Rust is really awesome change!
@awwastor
@awwastor 2 жыл бұрын
Wow, those videos are amazing!
@hos7012
@hos7012 Жыл бұрын
this is the best way of illustration 🎉
@leftyhero147
@leftyhero147 2 жыл бұрын
Hey man, I have a suggestion. It would be cool if you do a video about iterators but instead of showing how to build them, would be showing the most used iterators from the std library and showing practical applications. It would be of great value.
@elliott614
@elliott614 2 жыл бұрын
that's a topic that's been EXTREMELY widely covered online from a plethora of sources and in many languages. To be Rust-specific it makes sense to show how to create iterators in Rust vs. a video about iterators in general
@elliott614
@elliott614 2 жыл бұрын
all iterators no matter the collection type being encapsulated do the same thing. Just let's you get a reference to the next or previous item in the collection, and dereferencing operator gives the value. That's basically it. The only deeper you get is say, reverse iterators, const iterators, random access iterators, custom access order iterators ... which basically is the topic here (along with if you have a custom type with no iterators defined, defining it)
@elliott614
@elliott614 2 жыл бұрын
a very useful application is an unordered set of values (or an unordered / hash map). it'd be very very difficult to have to implement a way to do that every time. that's why we have iterators. Same with iterating over any type of graph or tree and guaranteeing you'll see each item exactly once before reaching the end
@alexo4600
@alexo4600 3 жыл бұрын
Rust gang best gang 🦀
@Undead34
@Undead34 3 ай бұрын
Muchas gracias amo estos videos!! Saludos desde Venezuela.
@exoticcoder5365
@exoticcoder5365 3 жыл бұрын
interesting on the last test 👍🏻
@caveofmovies8597
@caveofmovies8597 3 жыл бұрын
FINALLY!
@jaysistar2711
@jaysistar2711 2 жыл бұрын
Async iterators (I think the future crate calls them Stream) would be interesting.
@syedhuzaifaali57
@syedhuzaifaali57 2 жыл бұрын
What are the extensions you are using?
@dsons
@dsons 2 жыл бұрын
can you do a video on generators in rust?
@codychan4992
@codychan4992 2 жыл бұрын
It took me quite a while to understand the expression(12:46) of `let sum` line but failed, I don't know why the first pair of `Counter::new().zip(Counter::new().skip(1))` is (1, 2) instead of (0, 1), and why the second `Counter::new()` will use the first `Counter::new()`'s value to `skip(1)`?
@RocketmanReal
@RocketmanReal 2 жыл бұрын
Why do you think so? I believe the first pair is indeed (0, 1), and the second Counter::new() has it's own fresh count == 0 (count == 1 after skip()). So zip operation will return [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5)]. Then multiply each pair with map and we got [0, 2, 6, 12, 20]. Filter those who can divide by 3: [6, 12]. And it's sum is 18.
@pdblouin
@pdblouin 2 жыл бұрын
@@RocketmanReal 1) Why doesn't zip return (5, None) after (4,5)? I guess this is built into the implementation? 2) Where are values "a", "b", and "x" defined? It seems like magic that the compiler knows which values to use here.
@RocketmanReal
@RocketmanReal 2 жыл бұрын
@@pdblouin​ ​ ​1) yeah, I believe that’s built in to stop iterating when you reach None. It’s the same behavior as if you use any other method, like map, filter, etc - last iteration won’t return a None, just the last element. 2) First, these variables are defined inside of a closure function that you pass as argument into .map(). But you cannot pass any closure inside. Because of map’s type definition. .map() is a generic function, that will only take a closure with an argument of the same type, as the value you call the .map() on.
@siljamickeify
@siljamickeify 6 ай бұрын
Thanks for great videos! A question, if I can give my own types the Iterator trait, how is it a given that my type can always be summed by the default sum() function? Maybe my type is not possible to sum meaningfully? But it may still be some sort of collection that can be meaningfully traversed, so the next function may be straight forward. I don't get it?
@siljamickeify
@siljamickeify 6 ай бұрын
@@stefano_schmidt So not really sum, but actually more like "count" then?
@siljamickeify
@siljamickeify 6 ай бұрын
[5,6,3] is 3 and not 14?
@stefano_schmidt
@stefano_schmidt 6 ай бұрын
​@@siljamickeifyuh, yeah, you're right. nvm
@davidpottage6402
@davidpottage6402 4 ай бұрын
This question triggered my curiosity so I went digging into the standard library. I had assumed that via type system magic, the sum method is only valid on iterators of numbers, but that is not quite how it works. Instead sum will also work on references adding up the total size of the items. So if you list of items are Stings ["1", "20", "300" ] then sum will add up the string lengths and give you 6. In comparison if you did the same thing in a scripting language such as Perl, it would convert those strings to numbers and return 321.
@siljamickeify
@siljamickeify 4 ай бұрын
@davidpottage6402 hmm, that was rather counterintuitive if you ask me. I guess I'm missing something? Is this standard nomenclature nowadays? Does other languages similar constructs use the name "sum" in the same way? If so, the I buy it, but if Rust has its own definition, them I feel I must be missing the point? But thanks to YOU for the dig into the std! Really interesting!
@daminatilada6093
@daminatilada6093 2 жыл бұрын
I got an error on zip() and skip method. it's not available.
@Koynst
@Koynst 2 жыл бұрын
probably you are working on the same file from the beginning of video, right? Then you still have `pub trait Iterator { //..} from 2:33 which shadow default Iterator from Rust library. Just commented and it will work.
@luizneri
@luizneri 2 жыл бұрын
The last example got me bugged. By skipping 1, you made iterators of different sizes, so why didn't you get a=5 and b=none?
@edwardweir5784
@edwardweir5784 2 жыл бұрын
The output iterator from .zip returns None if either input iterator would return None. In other words, the output iterator only has as many items as the smallest of the two input iterators.
@student99bg
@student99bg Жыл бұрын
Closures are basically like lambdas, right?
@jonforhan9196
@jonforhan9196 Жыл бұрын
Yes
@alexbork4250
@alexbork4250 22 күн бұрын
lamba is usually just anonymous function, but closures have access to context of current method if they need (like access to local variable)
@Prabh_cc
@Prabh_cc Жыл бұрын
Confusing 😅
@bbantsadze
@bbantsadze Жыл бұрын
I smell rxjs here
@jabuci
@jabuci 2 жыл бұрын
How to add this functionality? let cnt = Counter::new(); for n in cnt.iter() { println!("{}", n); }
@GolangDojo
@GolangDojo 3 жыл бұрын
Only noobs use map and filter
@hermannpaschulke1583
@hermannpaschulke1583 3 жыл бұрын
What do pros use?
@GAGONMYCOREY
@GAGONMYCOREY 3 жыл бұрын
I don't trust the ministry. If you think about how tall my dad is and your dad, my dad is much taller.
@letsgetrusty
@letsgetrusty 3 жыл бұрын
Don't trigger the Rust gang lol
@abhinavchavali1443
@abhinavchavali1443 3 жыл бұрын
Especially in Python
Iterators in Practice
7:00
Let's Get Rusty
Рет қаралды 20 М.
Closures in Rust
19:53
Let's Get Rusty
Рет қаралды 75 М.
لااا! هذه البرتقالة مزعجة جدًا #قصير
00:15
One More Arabic
Рет қаралды 24 МЛН
IQ Level: 10000
00:10
Younes Zarou
Рет қаралды 12 МЛН
1,000 Diamonds! (Funny Minecraft Animation) #shorts #cartoon
00:31
toonz CRAFT
Рет қаралды 41 МЛН
SPILLED CHOCKY MILK PRANK ON BROTHER 😂 #shorts
00:12
Savage Vlogs
Рет қаралды 8 МЛН
Intro to async/.await in Rust
13:57
Let's Get Rusty
Рет қаралды 85 М.
State Design Pattern in Rust
20:21
Let's Get Rusty
Рет қаралды 41 М.
The Box Smart Pointer in Rust
12:18
Let's Get Rusty
Рет қаралды 69 М.
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 159 М.
Faster than Rust and C++: the PERFECT hash table
33:52
strager
Рет қаралды 534 М.
You Should Really Know These Traits in Rust
18:36
Oliver Jumpertz
Рет қаралды 12 М.
The standard library now has all you need for advanced routing in Go.
13:52
Error Handling in Rust
16:20
Let's Get Rusty
Рет қаралды 84 М.
Understanding Ownership in Rust
25:31
Let's Get Rusty
Рет қаралды 249 М.
لااا! هذه البرتقالة مزعجة جدًا #قصير
00:15
One More Arabic
Рет қаралды 24 МЛН