japaric/rust-by-example — pull request #205 by cybergeek94 (2014-07-29 04:13:53+00:00)
Title: hash: HashMap, custom key types, HashSet, and SmallIntMap

My body is ready.

I learned a lot with `git` while trying to squash a pile of tiny commits and make the whole thing more coherent.

It's up to you to decide whether it's inappropriate, but I wanted to keep the examples slightly tongue-in-cheek while staying somewhat realistic to be easier to understand.

The `SmallIntMap` example probably would have worked better as `Vec`, honestly, but it was hard figuring out a good use case for it.

Funny story, in [`move_in`][1] I wanted to do something clever with a mutable iterator, by finding the first `None` and replacing it with `Some(Tenant)`. But `SmallIntMap` was too smart for me, and the iterator yielded `Tenant` instead of `Option`.

I was able to clean up the `hash` example. It turns out the problem was keeping a local reference to the result of `find`, which I understand now.

Closes #161.

[1]: https://github.com/cybergeek94/rust-by-example/commit/fc404313d5fb762a4100599f636a0b708f07bbbd#diff-c74886d107b5d138c37067d36f6ae691R10