Searching with Iterators using Structs
Explore how to search structured data in Rust using iterators to process collections efficiently. Understand the find method for locating elements, the Option enum for safe value handling, and match statements to work with search results in your Rust game development projects.
We'll cover the following...
Though visitors are now represented as structures, we still need to be able to search them. We could use the same search code as before, comparing your_name with visitor.name to call the greeting method directly, but this method isn’t ideal. This gets unwieldy as our visitors become more complicated and we add more visitors to the list.
[package] name = "treehouse_guestlist_struct" version = "0.1.0" authors = ["Herbert Wolverson <herberticus@gmail.com>"] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies]
Iterators
Rust provides a powerful feature known as iterators to manipulate data. Iterators can do a lot.
When working with lists of data, iterators are the first place to look for the functionality we need. Iterators are designed around function chaining. Each iterator step works as a building block to massage the data from the previous step into what we need. ...