use std::{
borrow::Cow,
path::{Path, PathBuf},
};
pub struct TemplateSpec {
pub path: PathBuf,
pub features: Vec<&'static str>,
}
impl TemplateSpec {
pub fn get_path<P: AsRef<Path>>(&self, base_path: P) -> Cow<'_, Path> {
if self.path.is_relative() {
Cow::Owned(base_path.as_ref().join(&self.path))
} else {
Cow::Borrowed(self.path.as_path())
}
}
}
impl From<&str> for TemplateSpec {
fn from(path: &str) -> Self {
Self {
path: path.into(),
features: vec![],
}
}
}
impl From<&&str> for TemplateSpec {
fn from(path: &&str) -> Self {
Self {
path: path.into(),
features: vec![],
}
}
}
impl From<&Path> for TemplateSpec {
fn from(path: &Path) -> Self {
Self {
path: path.to_path_buf(),
features: vec![],
}
}
}
impl From<PathBuf> for TemplateSpec {
fn from(path: PathBuf) -> Self {
Self { path, features: vec![] }
}
}
impl From<(&str, &[&'static str])> for TemplateSpec {
fn from((path, features): (&str, &[&'static str])) -> Self {
Self {
path: path.into(),
features: features.to_vec(),
}
}
}