hawkw / sharded-slab

a lock-free concurrent slab (experimental)
MIT License
273 stars 19 forks source link

Document semantics of Slab::unique_iter #77

Closed jplatte closed 1 year ago

jplatte commented 1 year ago

I had to read the source code to find out that UniqueIter yields references. It's also unclear what happens if new items are pushed while the iterator is alive.

hawkw commented 1 year ago

I had to read the source code to find out that UniqueIter yields references.

I think this is because the UniqueIter type itself is private, so its Iterator implementation can't be viewed in the RustDoc. We should probably go ahead and make the type public.

It's also unclear what happens if new items are pushed while the iterator is alive.

Because constructing a UniqueIter mutably borrows the slab, it has exclusive access to the slab while the iterator is alive. This means that no new items can be inserted or removed while iterating. So, new items cannot be added until the iteration is complete. This is why UniqueIter takes &mut self.

hawkw commented 1 year ago

I've added some additional documentation in #87. Hopefully that helps!