Jan :rust: :ferris: · @janriemer
513 followers · 2898 posts · Server floss.social

Oh wow, did you know that in 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:
play.rust-lang.org/?version=st

This trick is right from the docs on option:

doc.rust-lang.org/stable/std/o

What a cunning trick!🤓

Rust, I ❤️ you!

#Rust #RustTip #rusttips #rustlang

Last updated 2 years ago

Jan · @janriemer
340 followers · 373 posts · Server floss.social

@follpvosten Nice! 👍

Ok, I'll continue...🙂

✨ did you know ✨

Since 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")]);

doc.rust-lang.org/std/collecti

#RustTip #rustlang #Rust

Last updated 3 years ago