So… apparently I keep screwing up uses of
HashSet::insert (I essentially get it wrong every time, even when I explicitly think about it). My problem seems to be that
Some(foo) if the value already existed, while
false if the value already existed.
The reasoning behind that is that
true if the value was inserted (meaning it didn’t already exist). This is all sound, but I still kind of think of a
Some as a
true with data. So these two methods, even though they do almost the same, have the exact opposite return value.
I mean, I get all that, and the docs on it are good, but is anyone else also having issues with correctly calling that method? If this is an issue and not just carelessness on my part, we should probably put some thought into how to prevent such bugs.
Not sure how to solve this, but some ideas:
HashSetand prefer a new
try_insert, which gives you your value back if it couldn’t be inserted
HashSetand prefer some new method which gives you the old value back and inserts yours
- create some smart lint that figures out whether you need