resource_path/third_party/
display.rs1use std::{
2 fmt::{Debug, Display, Formatter},
3 path::PathBuf,
4 str::FromStr,
5};
6
7use url::{ParseError, Url};
8
9use crate::ResourcePath;
10
11impl Debug for ResourcePath {
12 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
13 f.debug_struct("ResourcePath").field("network", &self.remote.as_str()).field("local", &self.local).finish()
14 }
15}
16
17impl Display for ResourcePath {
18 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
19 write!(f, "{}?local={}", self.remote, self.local.display())
20 }
21}
22
23impl FromStr for ResourcePath {
24 type Err = ParseError;
25
26 fn from_str(s: &str) -> Result<Self, Self::Err> {
27 let mut url = Url::parse(s)?;
28 let mut local = PathBuf::from(".");
29 for (key, value) in url.query_pairs() {
30 match key.as_ref() {
31 "local" | "relative" => local = PathBuf::from(value.as_ref()),
32 _ => {}
33 }
34 }
35 url.set_query(None);
36 Ok(Self { remote: url, local })
37 }
38}