Oh wow, did you know that in #Rust you can use Option as an iterator such that your types align, when you want to return a chain of iterators from a function, but also have an else case where the iterator is empty!?
I know, this was a mouthful.😳
Let's look at a playground that shows this:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=129eb419d767b71447b408e456773555
This trick is right from the docs on option:
https://doc.rust-lang.org/stable/std/option/#iterating-over-option
What a cunning trick!🤓
Rust, I ❤️ you!
#Rust #RustTip #rusttips #rustlang
@follpvosten Nice! 👍
Ok, I'll continue...🙂
✨ did you know ✨
Since #Rust 1.56, std::collections::HashMap<K,V> impls From<[(K, V); N]>
This means the simplest way to create a HashMap is now:
HashMap::from([(1, "Love"), (2, "Rust")]);