boxcar icon indicating copy to clipboard operation
boxcar copied to clipboard

`Debug` output of `Vec` should show gaps

Open clarfonthey opened this issue 1 year ago • 0 comments

Just to track this so it doesn't get lost.

Was looking into this and it appears a bit more complicated than initially thought. A few thoughts on what would help enable this.

First, there should probably be some sort of "entry API" in the sense of some opaque Entry<'_, T> type that represents a spot in the vec. Essentially, as long as the index of the entry is in-bounds, the entry would be returned, but you can't actually get a reference to the underlying element until it's ready. It should have at least a "try access" method that returns Option<&T>.

Second, there should be an iterator that returns these entries in the correct order. Reading the code for iter, I know that gaps are allowed, but it appears that they're also allowed to be returned out-of-order. This would allow stuff like enumerate() to work properly without having to track indices separately.

Third, we could easily use this new iterator for Debug to display gaps based upon the "try access" method.

clarfonthey avatar Sep 22 '24 18:09 clarfonthey