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