Popular Rust Iterator Methods 🦀

preview_player
Показать описание
Rust iterators are incredibly powerful, allowing you to manipulate collections of various data structures. Because the Iterator Trait defines this functionality, these useful methods can be found on any custom types that implement it. While we don't have enough time to cover *all* of these methods, we will explore some of the more common methods, and spend some hands-on time with them.

For example, we can take a second iterable collection, and .chain() it to the first one. We can also .zip() collections together into tuple types. You can perform filters, data transformations, and much more, using the Rust iterator methods. I strongly encourage you to spend some time using these methods, to ensure that you understand how they work, when you actually need them.

Please follow me on these other social channels!

All trademarks, logos and brand names are the property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names,trademarks and brands does not imply endorsement.

#rustlang #rust #rustdev #opensource #software #linux #devops #programming #rusty #dev #coding #codinglife #code #coder #ubuntu #ubuntulinux #appdev #developer
Рекомендации по теме
Комментарии
Автор

You can simplify transforming a Vec<&str> into a Vec<String> by using vec_of_str.map(String::from) instead of using a full closure. This works because .map requires that the function you use takes the same type and number of arguments as the items in the vector. In this case, String::from fits perfectly as it takes a single &str argument and is not a method of &str, but rather a function that operates on &str to produce a String.

irlshrek
Автор

This is the exact type of content i was looking for learning rust. Many educators just copy the content from the rust book and severely lack originality and explanation.

thedarkknight-
Автор

Chapter 13.2 in the rust book seems to assume the reader has more experience with iterators than I did when reading it. This video helps fill in some of those gaps, thanks!

trevorbeingtrevor
Автор

Thanks for the video. I learnt a few new useful methods here. Can you please make the text wrap around so it doesn’t go off the screen?

johndavies
Автор

Thank you for these videos. They are really helpful. The quality of content is far better than the paid subscription I use.

If I can suggest, it would be nice to see a detailed video on smart pointers, their necessity, usage etc. Thanks.

stevedsouza
Автор

Thanks for this.

I think it’s useful for beginners to know that you can use the variable name in format strings - e.g. println!(“{index} {value:?}”);

This can save quite a lot of typing when starting out. Unfortunately it’s not quite as powerful as Python’s f-strings, as you can’t put any expression in the {} like {value.0}. I feel like this is an unfortunate omission since Rust is so expression-based. Oh well :)

I think sum(), product() and count() are more useful and intuitive to beginners than fold(), but it’s good to mention it for more complex items like those quantity tuples. I’m just slightly surprised you went there so quickly :)

meowsqueak
Автор

Very helpful video, like the others in this series.

isn't &str a borrowed string slice and not a static string? A static string has a lifetime equal to the whole program, whereas the lifetime of &str may not be.

ChidleyITCompute
Автор

never learnt this much from any other video

ImranKhan-brdv
Автор

Hi Trevor. I have a question.
for fruit: &&str in fruit_iter{
println!("{}", fruit);
}
why the type of fruit is &&str instead of &str?
Thank you!

bujibujibuji-zz
Автор

Is the source code that you worked on in this video available somewhere?

alokswaincontact
Автор

my rust programs are over 2Gb can you make a video on how to minimize the size of binaries ??

skull_cyber