use super::VirtualPath;
pub struct VirtualReadDir<'a, Marker> {
pub(super) inner: std::fs::ReadDir,
pub(super) parent: &'a VirtualPath<Marker>,
}
impl<Marker> std::fmt::Debug for VirtualReadDir<'_, Marker> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("VirtualReadDir")
.field("parent", &self.parent.virtualpath_display().to_string())
.finish_non_exhaustive()
}
}
impl<Marker: Clone> Iterator for VirtualReadDir<'_, Marker> {
type Item = std::io::Result<VirtualPath<Marker>>;
fn next(&mut self) -> Option<Self::Item> {
match self.inner.next()? {
Ok(entry) => {
let file_name = entry.file_name();
match self.parent.virtual_join(file_name) {
Ok(virtual_path) => Some(Ok(virtual_path)),
Err(e) => Some(Err(std::io::Error::new(std::io::ErrorKind::InvalidData, e))),
}
}
Err(e) => Some(Err(e)),
}
}
}