diff --git a/fat-bits/src/lib.rs b/fat-bits/src/lib.rs index 0709cce..f17275c 100644 --- a/fat-bits/src/lib.rs +++ b/fat-bits/src/lib.rs @@ -2,7 +2,7 @@ use std::cell::RefCell; use std::io::{Read, Seek, SeekFrom, Write}; use std::rc::Rc; -use crate::dir::{DirEntry, DirIter}; +use crate::dir::DirIter; use crate::fat::{FatError, Fatty}; use crate::subslice::{SubSlice, SubSliceMut}; @@ -217,7 +217,12 @@ impl FatFs { Ok(data) } - pub fn root_dir_iter(&self) -> Box + '_> { + fn chain_reader(&self, first_cluster: u32) -> impl Read { + iter::ClusterChainReader::new(self, first_cluster) + } + + pub fn root_dir_iter<'a>(&'a self) -> DirIter> { + // Box + '_> // TODO: maybe wrap this in another RootDirIter enum, so we don't have to Box if let Some(root_dir_offset) = self.root_dir_offset { @@ -225,7 +230,7 @@ impl FatFs { let sub_slice = SubSlice::new(self, root_dir_offset, self.root_dir_size); - return Box::new(DirIter::new(sub_slice)); + return DirIter::new(Box::new(sub_slice)); } // FAT32 @@ -235,10 +240,15 @@ impl FatFs { let cluster_iter = iter::ClusterChainReader::new(self, root_cluster); - Box::new(DirIter::new(cluster_iter)) + DirIter::new(Box::new(cluster_iter)) } - pub fn chain_reader(&self, first_cluster: u32) -> impl Read { - iter::ClusterChainReader::new(self, first_cluster) + pub fn dir_iter<'a>(&'a self, first_cluster: u32) -> DirIter> { + // TODO: return type must match root_dir_iter + // if the Box is changed there, update here as well + + let cluster_iter = self.chain_reader(first_cluster); + + DirIter::new(Box::new(cluster_iter)) } } diff --git a/fat-dump/src/main.rs b/fat-dump/src/main.rs index 3cb84eb..b2fe7c3 100644 --- a/fat-dump/src/main.rs +++ b/fat-dump/src/main.rs @@ -68,9 +68,7 @@ fn tree(fat_fs: &FatFs, show_hidden: bool) { } if dir_entry.is_dir() { - let reader = fat_fs.chain_reader(dir_entry.first_cluster()); - - let iter = DirIter::new(reader); + let iter = fat_fs.dir_iter(dir_entry.first_cluster()); tree_impl(fat_fs, iter, show_hidden, indent + 1); }