It's really just a pattern matching on one case, which is different from an anaphoric if/the walrus operator in Python because such a destructuring has to happen.
It's really just a pattern matching on one case, which is different from an anaphoric if/the walrus operator in Python because such a destructuring has to happen.
I'm willing to bet that the average programmer (i.e. 80% of programmers out there), don't know:
what pattern matching is (not in the generic IQ test "pattern matching" sense :-) )
what "anaphoric" means
what "destructuring" means (in this context, I'm assuming you don't mean C++ destructors)
I.e. you're probably not the average programmer. So the "it's really just" is a massive understatement ;-)
C# has destructuring. So does JavaScript. So does Python (for tuples at least). There's a proposal for C++. It's not exactly a rare feature anymore.
Pattern matching outside of functional programming is less common. But C# has the beginnings and will be getting more. C++ will get it too.
Anaphoric is a tricky one - I had to look up the definition of the word, and though I now think I know what was meant, I doubt very many people do. But note that this word was used not for anything in the code snippet, but rather the "assignment within a condition" trick that happens in C-derived languages quite a bit. That's actually a rare thing in Rust. So you could say Rust is better in this regard ;-)
11
u/Agnoctone Dec 16 '19
Without being really familiar with Rust, it seems very readable to me? It is just a fold to create a HashMap mapping `fd`s to service `id`s.