use crate::index::DirIndex;
use crate::scan::Scanner;
use std::fs::File;
use std::fs::Metadata;
use std::io;
use std::path::Path;
use std::path::PathBuf;
#[derive(Clone, Debug)]
pub struct ScanOptions {
pub(super) one_file_system: bool,
pub(super) add_prefix: Option<PathBuf>,
}
impl ScanOptions {
#[inline]
pub fn new() -> Self {
Self {
one_file_system: false,
add_prefix: None,
}
}
#[inline]
pub fn one_file_system(&mut self, one_file_system: bool) -> &mut Self {
self.one_file_system = one_file_system;
self
}
#[inline]
pub fn add_prefix(&mut self, prefix: PathBuf) -> &mut Self {
self.add_prefix = Some(prefix);
self
}
#[inline]
pub fn scan_with<'i, T, P, F>(
&self,
index: &'i mut DirIndex<T>,
path: P,
generator: F,
) -> io::Result<Scanner<'i, T, F>>
where
P: AsRef<Path>,
F: FnMut(&Path, &mut File, &Metadata) -> io::Result<T>,
{
Scanner::new(self.clone(), index, path, generator)
}
#[inline]
pub fn scan<'i, T, P>(
&self,
index: &'i mut DirIndex<T>,
path: P,
) -> io::Result<Scanner<'i, T, impl FnMut(&Path, &mut File, &Metadata) -> io::Result<T>>>
where
T: Default,
P: AsRef<Path>,
{
self.scan_with(index, path, |_, _, _| Ok(T::default()))
}
}
impl Default for ScanOptions {
#[inline]
fn default() -> Self {
Self::new()
}
}