summaryrefslogtreecommitdiffstats
path: root/vendor/sharded-slab/src/lib.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/sharded-slab/src/lib.rs
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/sharded-slab/src/lib.rs')
-rw-r--r--vendor/sharded-slab/src/lib.rs26
1 files changed, 20 insertions, 6 deletions
diff --git a/vendor/sharded-slab/src/lib.rs b/vendor/sharded-slab/src/lib.rs
index e57cf50e2..ea9b66de3 100644
--- a/vendor/sharded-slab/src/lib.rs
+++ b/vendor/sharded-slab/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,15 +738,26 @@ impl<T, C: cfg::Config> Slab<T, C> {
}
/// Returns an iterator over all the items in the slab.
+ ///
+ /// Because this iterator exclusively borrows the slab (i.e. it holds an
+ /// `&mut Slab<T>`), 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");
- let mut pages = shard.iter();
- let slots = pages.next().and_then(page::Shared::iter);
+
+ let (pages, slots) = match shards.next() {
+ Some(shard) => {
+ let mut pages = shard.iter();
+ let slots = pages.next().and_then(page::Shared::iter);
+ (pages, slots)
+ }
+ None => ([].iter(), None),
+ };
+
iter::UniqueIter {
shards,
- slots,
pages,
+ slots,
}
}
}