Skip to main content

winget_types/url/
package_url.rs

1use core::{fmt, str::FromStr};
2
3use url::ParseError;
4
5use super::DecodedUrl;
6
7#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord, Hash)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[cfg_attr(feature = "serde", serde(transparent))]
10pub struct PackageUrl(DecodedUrl);
11
12impl PackageUrl {
13    /// Returns the serialization of this URL.
14    #[inline]
15    pub fn as_str(&self) -> &str {
16        self.0.as_str()
17    }
18}
19
20impl AsRef<str> for PackageUrl {
21    fn as_ref(&self) -> &str {
22        self.0.as_ref()
23    }
24}
25
26impl fmt::Display for PackageUrl {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        self.0.fmt(f)
29    }
30}
31
32impl FromStr for PackageUrl {
33    type Err = ParseError;
34
35    #[inline]
36    fn from_str(src: &str) -> Result<Self, Self::Err> {
37        DecodedUrl::from_str(src).map(Self)
38    }
39}