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