use std::path::{Path, PathBuf};
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum FileLocation {
Path(PathBuf),
Uri(String),
}
impl FileLocation {
pub fn from_path<P: AsRef<Path>>(path: P) -> Self {
Self::Path(path.as_ref().to_owned())
}
pub fn from_uri(uri: impl Into<String>) -> Self {
Self::Uri(uri.into())
}
pub fn path(&self) -> Option<&Path> {
match self {
Self::Path(path) => Some(path),
Self::Uri(_) => None,
}
}
pub fn uri(&self) -> Option<&str> {
match self {
Self::Path(_) => None,
Self::Uri(uri) => Some(uri),
}
}
pub fn into_path(self) -> Option<PathBuf> {
match self {
Self::Path(path) => Some(path),
Self::Uri(_) => None,
}
}
pub fn into_uri(self) -> Option<String> {
match self {
Self::Path(_) => None,
Self::Uri(uri) => Some(uri),
}
}
}