winget_types/installer/
installer_type.rs1use core::{fmt, str::FromStr};
2
3use thiserror::Error;
4
5use super::nested::installer_type::NestedInstallerType;
6
7#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
10#[non_exhaustive]
11pub enum InstallerType {
12 Msix,
13 Msi,
14 Appx,
15 Exe,
16 Zip,
17 Inno,
18 Nullsoft,
19 Wix,
20 Burn,
21 Pwa,
22 Portable,
23 Font,
24}
25
26impl InstallerType {
27 #[must_use]
28 pub const fn as_str(self) -> &'static str {
29 match self {
30 Self::Msix => "msix",
31 Self::Msi => "msi",
32 Self::Appx => "appx",
33 Self::Exe => "exe",
34 Self::Zip => "zip",
35 Self::Inno => "inno",
36 Self::Nullsoft => "nullsoft",
37 Self::Wix => "wix",
38 Self::Burn => "burn",
39 Self::Pwa => "pwa",
40 Self::Portable => "portable",
41 Self::Font => "font",
42 }
43 }
44}
45
46impl AsRef<str> for InstallerType {
47 #[inline]
48 fn as_ref(&self) -> &str {
49 self.as_str()
50 }
51}
52
53impl TryFrom<InstallerType> for NestedInstallerType {
54 type Error = ();
55
56 fn try_from(value: InstallerType) -> Result<Self, Self::Error> {
57 match value {
58 InstallerType::Msix => Ok(Self::Msix),
59 InstallerType::Msi => Ok(Self::Msi),
60 InstallerType::Appx => Ok(Self::Appx),
61 InstallerType::Exe => Ok(Self::Exe),
62 InstallerType::Inno => Ok(Self::Inno),
63 InstallerType::Nullsoft => Ok(Self::Nullsoft),
64 InstallerType::Wix => Ok(Self::Wix),
65 InstallerType::Burn => Ok(Self::Burn),
66 InstallerType::Portable => Ok(Self::Portable),
67 InstallerType::Font => Ok(Self::Font),
68 InstallerType::Zip | InstallerType::Pwa => Err(()),
69 }
70 }
71}
72
73impl fmt::Display for InstallerType {
74 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75 self.as_str().fmt(f)
76 }
77}
78
79#[derive(Error, Debug, Eq, PartialEq)]
80#[error("Installer type did not match a valid lowercase installer type")]
81pub struct InstallerTypeParseError;
82
83impl FromStr for InstallerType {
84 type Err = InstallerTypeParseError;
85
86 fn from_str(s: &str) -> Result<Self, Self::Err> {
87 match s {
88 "msix" => Ok(Self::Msix),
89 "msi" => Ok(Self::Msi),
90 "appx" => Ok(Self::Appx),
91 "exe" => Ok(Self::Exe),
92 "zip" => Ok(Self::Zip),
93 "inno" => Ok(Self::Inno),
94 "nullsoft" => Ok(Self::Nullsoft),
95 "wix" => Ok(Self::Wix),
96 "burn" => Ok(Self::Burn),
97 "pwa" => Ok(Self::Pwa),
98 "portable" => Ok(Self::Portable),
99 "font" => Ok(Self::Font),
100 _ => Err(InstallerTypeParseError),
101 }
102 }
103}