mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Use std::slice::Iter instead of manually tracking the offset
This commit is contained in:
17
src/blob.rs
17
src/blob.rs
@@ -514,7 +514,7 @@ impl<'a> BlobDirContents<'a> {
|
||||
}
|
||||
|
||||
pub(crate) fn iter(&self) -> BlobDirIter<'_> {
|
||||
BlobDirIter::new(self.context, &self.inner)
|
||||
BlobDirIter::new(self.context, self.inner.iter())
|
||||
}
|
||||
|
||||
pub(crate) fn len(&self) -> usize {
|
||||
@@ -524,18 +524,13 @@ impl<'a> BlobDirContents<'a> {
|
||||
|
||||
/// A iterator over all the [`BlobObject`]s in the blobdir.
|
||||
pub(crate) struct BlobDirIter<'a> {
|
||||
paths: &'a [PathBuf],
|
||||
offset: usize,
|
||||
iter: std::slice::Iter<'a, PathBuf>,
|
||||
context: &'a Context,
|
||||
}
|
||||
|
||||
impl<'a> BlobDirIter<'a> {
|
||||
fn new(context: &'a Context, paths: &'a [PathBuf]) -> BlobDirIter<'a> {
|
||||
Self {
|
||||
paths,
|
||||
offset: 0,
|
||||
context,
|
||||
}
|
||||
fn new(context: &'a Context, iter: std::slice::Iter<'a, PathBuf>) -> BlobDirIter<'a> {
|
||||
Self { iter, context }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,9 +538,7 @@ impl<'a> Iterator for BlobDirIter<'a> {
|
||||
type Item = BlobObject<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
while let Some(path) = self.paths.get(self.offset) {
|
||||
self.offset += 1;
|
||||
|
||||
while let Some(path) = self.iter.next() {
|
||||
// In theory this can error but we'd have corrupted filenames in the blobdir, so
|
||||
// silently skipping them is fine.
|
||||
match BlobObject::from_path(self.context, path) {
|
||||
|
||||
Reference in New Issue
Block a user