Open
Description
(Originally filed as rust-lang/rust#37986, but a pre-RFC belongs in the RFC repo, not the rust repo. Re-filing it here.)
I'd like to have a pop()
method available for HashSet
, which removes an item from the set if any, and returns an Option<T>
(returning None
if empty). That would make it easy to iterate over a set with while let element = set.pop() { ... }
, without holding a mutable reference to the set as HashSet::drain()
does, so you can insert more items into the set as you iterate.
Does that seem like a reasonable method to add to HashSet? Does this need an RFC, or just a patch to std?