How to do error handling in Rust and what are the common pitfalls?

Rust generally solves errors in two ways: Unrecoverable errors. Once you panic!, that’s it. Your program or thread aborts because it encounters something it can’t solve and its invariants have been violated. E.g. if you find invalid sequences in what should be a UTF-8 string. Recoverable errors. Also called failures in some documentation. Instead of … Read more

How do I create a HashMap with type erased keys?

It seems like I could create a Hasher (e.g. RandomState), use that to manually calculate hash values, then store the u64 result in a HashMap<u64, _> but that seems kind of overly complex. Unfortunately that’s overly simple – since a hash function discards some information, hash tables don’t just work on hashes, they also need … Read more

Comparing every element in a vector with the next one

This can be done in several ways. Using slice::windows slice::windows: Returns an iterator over all contiguous windows of length size. In this case, the window size will be 2 so windows will return an iterator which will mask 2 elements and it will move to the right on every iteration. initial position : [|0, 5|, … Read more