41 lines
1.2 KiB
Rust
41 lines
1.2 KiB
Rust
use crate::driver_filesystem::filesystem_resource::FilesystemResourceLocation;
|
|
use crate::resource::{DynResource, DynResourceLocation, Resource, ResourceLocation};
|
|
use crate::source::ResourceSource;
|
|
use std::io::Sink;
|
|
use std::path::PathBuf;
|
|
use walkdir::WalkDir;
|
|
|
|
pub struct DirectorySource {
|
|
location: String,
|
|
iter: walkdir::IntoIter,
|
|
}
|
|
impl DirectorySource {
|
|
pub fn open_dir(location: String) -> Self {
|
|
let iter = WalkDir::new(location.clone()).into_iter();
|
|
DirectorySource { location, iter }
|
|
}
|
|
}
|
|
|
|
impl ResourceSource for DirectorySource {
|
|
fn location(&self) -> DynResourceLocation {
|
|
Box::new(FilesystemResourceLocation::from(PathBuf::from(
|
|
self.location.clone(),
|
|
)))
|
|
}
|
|
}
|
|
|
|
impl Iterator for DirectorySource {
|
|
type Item = DynResourceLocation;
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
use crate::resource::ResourceLocation;
|
|
self.iter
|
|
.next()
|
|
.map(|entry| entry.unwrap())
|
|
.map(|entry| entry.path().to_path_buf())
|
|
.map(|entry| {
|
|
let loc = FilesystemResourceLocation::from(entry);
|
|
Box::new(loc) as Box<dyn ResourceLocation>
|
|
})
|
|
}
|
|
}
|