diff --git a/src/iter.rs b/src/iter.rs index 54189aa..3b2a27c 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -1,6 +1,8 @@ use crate::{page, shard}; use std::slice; +/// An exclusive iterator over the items in a [`Slab`](crate::Slab). +#[must_use = "iterators are lazy and do nothing unless consumed"] #[derive(Debug)] pub struct UniqueIter<'a, T, C: crate::cfg::Config> { pub(super) shards: shard::IterMut<'a, Option, C>, diff --git a/src/lib.rs b/src/lib.rs index e57cf50..2f90438 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -215,8 +215,11 @@ mod page; mod shard; mod tid; -pub use cfg::{Config, DefaultConfig}; -pub use clear::Clear; +pub use self::{ + cfg::{Config, DefaultConfig}, + clear::Clear, + iter::UniqueIter, +}; #[doc(inline)] pub use pool::Pool; @@ -735,6 +738,10 @@ impl Slab { } /// Returns an iterator over all the items in the slab. + /// + /// Because this iterator exclusively borrows the slab (i.e. it holds an + /// `&mut Slab`), elements will not be added or removed while the + /// iteration is in progress. pub fn unique_iter(&mut self) -> iter::UniqueIter<'_, T, C> { let mut shards = self.shards.iter_mut(); let shard = shards.next().expect("must be at least 1 shard");