kxio/src/fs/dir.rs

23 lines
679 B
Rust
Raw Normal View History

2024-11-02 07:34:08 +00:00
//
use crate::fs::{DirItem, DirItemIterator, Result};
use super::path::{DirG, PathReal};
impl<'base, 'path> PathReal<'base, 'path, DirG> {
pub fn create(&mut self) -> Result<()> {
self.check_error()?;
std::fs::create_dir(self.as_pathbuf()).map_err(Into::into)
}
pub fn create_all(&mut self) -> Result<()> {
self.check_error()?;
std::fs::create_dir_all(self.as_pathbuf()).map_err(Into::into)
}
pub fn read(&mut self) -> Result<Box<dyn Iterator<Item = Result<DirItem>>>> {
self.check_error()?;
let read_dir = std::fs::read_dir(self.as_pathbuf())?;
Ok(Box::new(DirItemIterator::new(read_dir)))
}
}