use std::{fmt, path::PathBuf};
use http::Uri;
pub enum Source {
Path(PathBuf),
Url(Uri),
}
impl Source {
pub fn display_name(&self) -> String {
match self {
Self::Path(p) => p
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("asset")
.to_string(),
Self::Url(uri) => uri
.path()
.rsplit('/')
.find(|s| !s.is_empty())
.unwrap_or("asset")
.to_string(),
}
}
}
impl fmt::Display for Source {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Path(p) => p.display().fmt(f),
Self::Url(uri) => uri.fmt(f),
}
}
}