winget_types/shared/url/
mod.rs

1mod copyright_url;
2mod license_url;
3mod package_url;
4mod publisher_support_url;
5mod publisher_url;
6mod release_notes_url;
7
8use core::{
9    fmt,
10    ops::{Deref, DerefMut},
11    str::FromStr,
12};
13
14pub use copyright_url::CopyrightUrl;
15pub use license_url::LicenseUrl;
16pub use package_url::PackageUrl;
17use percent_encoding::percent_decode_str;
18pub use publisher_support_url::PublisherSupportUrl;
19pub use publisher_url::PublisherUrl;
20pub use release_notes_url::ReleaseNotesUrl;
21use url::{ParseError, Url};
22
23#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
24#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
25pub struct DecodedUrl(Url);
26
27impl DecodedUrl {
28    /// Returns the serialization of this URL.
29    #[inline]
30    pub fn as_str(&self) -> &str {
31        self.0.as_str()
32    }
33}
34
35impl AsRef<str> for DecodedUrl {
36    fn as_ref(&self) -> &str {
37        self.0.as_ref()
38    }
39}
40
41impl Default for DecodedUrl {
42    fn default() -> Self {
43        Self(Url::parse("https://example.com").unwrap_or_else(|_| unreachable!()))
44    }
45}
46
47impl Deref for DecodedUrl {
48    type Target = Url;
49
50    #[inline]
51    fn deref(&self) -> &Self::Target {
52        &self.0
53    }
54}
55
56impl DerefMut for DecodedUrl {
57    #[inline]
58    fn deref_mut(&mut self) -> &mut Self::Target {
59        &mut self.0
60    }
61}
62
63impl fmt::Display for DecodedUrl {
64    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65        self.0.fmt(f)
66    }
67}
68
69impl FromStr for DecodedUrl {
70    type Err = ParseError;
71
72    fn from_str(s: &str) -> Result<Self, Self::Err> {
73        Url::parse(&percent_decode_str(s).decode_utf8_lossy()).map(Self)
74    }
75}