1use std::path::PathBuf;
2use url::Url;
3
4#[derive(Debug)]
6pub enum RealizedHref {
7 PathBuf(PathBuf),
9
10 Url(Url),
12}
13
14impl From<&str> for RealizedHref {
15 fn from(s: &str) -> RealizedHref {
16 if stac::href::is_windows_absolute_path(s) {
17 return RealizedHref::PathBuf(PathBuf::from(s));
18 }
19 if let Ok(url) = Url::parse(s) {
20 if url.scheme() == "file" {
21 url.to_file_path()
22 .map(RealizedHref::PathBuf)
23 .unwrap_or_else(|_| RealizedHref::Url(url))
24 } else {
25 RealizedHref::Url(url)
26 }
27 } else {
28 RealizedHref::PathBuf(PathBuf::from(s))
29 }
30 }
31}