use std::path::PathBuf;
use super::FileFormat;
#[derive(Debug, Clone)]
pub struct FileSource {
pub(super) candidates: Vec<PathBuf>,
pub(super) required: bool,
pub(super) format: Option<FileFormat>,
}
impl FileSource {
#[must_use]
pub fn new(path: impl Into<PathBuf>) -> Self {
Self {
candidates: vec![path.into()],
required: true,
format: None,
}
}
#[must_use]
pub fn optional(path: impl Into<PathBuf>) -> Self {
Self {
candidates: vec![path.into()],
required: false,
format: None,
}
}
#[must_use]
pub fn search<I, P>(paths: I) -> Self
where
I: IntoIterator<Item = P>,
P: Into<PathBuf>,
{
Self {
candidates: paths.into_iter().map(Into::into).collect(),
required: true,
format: None,
}
}
#[must_use]
pub fn optional_search<I, P>(paths: I) -> Self
where
I: IntoIterator<Item = P>,
P: Into<PathBuf>,
{
Self {
candidates: paths.into_iter().map(Into::into).collect(),
required: false,
format: None,
}
}
#[must_use]
pub fn candidates(&self) -> &[PathBuf] {
&self.candidates
}
#[must_use]
pub fn format(mut self, format: FileFormat) -> Self {
self.format = Some(format);
self
}
}