[O] Return iterator instead

This commit is contained in:
Azalea Gui
2023-02-24 12:10:23 -05:00
parent c32055f213
commit 31842ef5a0
2 changed files with 3 additions and 5 deletions
+2 -3
View File
@@ -104,15 +104,14 @@ impl Generator {
pub fn encode_dir(&self, dir: &PathBuf) -> Result<()> { pub fn encode_dir(&self, dir: &PathBuf) -> Result<()> {
// Found file // Found file
Ok(()) Ok(())
} }
/// List all video files in a directory /// List all video files in a directory
pub fn list_video_files(&self, dir: &PathBuf) -> Vec<PathBuf> { pub fn list_video_files<'a>(&'a self, dir: &'a PathBuf) -> impl Iterator<Item = PathBuf> + 'a {
WalkDir::new(dir).into_iter().filter_map(|f| f.ok()) WalkDir::new(dir).into_iter().filter_map(|f| f.ok())
.filter(|f| f.path().is_file() && self.is_video(f)) .filter(|f| f.path().is_file() && self.is_video(f))
.map(|f| f.into_path()).collect() .map(|f| f.into_path())
} }
/// Check if a file is a video file by file name /// Check if a file is a video file by file name
+1 -2
View File
@@ -36,8 +36,7 @@ fn main() {
// let encoders = Encoders::load().unwrap(); // let encoders = Encoders::load().unwrap();
// info!("Encoders {:?}", encoders); // info!("Encoders {:?}", encoders);
let videos: Vec<PathBuf> = gen.list_video_files(&PathBuf::from("/data/Anime")).collect();
let videos = gen.list_video_files(&PathBuf::from("/data/Anime"));
videos.iter().for_each(|x| println!("Video found: {}", x.display())); videos.iter().for_each(|x| println!("Video found: {}", x.display()));
println!("Length: {}", videos.len()); println!("Length: {}", videos.len());
} }