winget_types/installer/switches/
custom.rs1use core::{
2 fmt,
3 ops::{Deref, DerefMut},
4 str::FromStr,
5};
6
7use compact_str::CompactString;
8
9use super::switch::{InstallerSwitch, SwitchError};
10
11#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13pub struct CustomSwitch(InstallerSwitch<2048>);
14
15impl CustomSwitch {
16 #[must_use]
17 pub fn all_users() -> Self {
18 "/ALLUSERS".parse().unwrap_or_else(|_| unreachable!())
19 }
20
21 #[must_use]
22 pub fn current_user() -> Self {
23 "/CURRENTUSER".parse().unwrap_or_else(|_| unreachable!())
24 }
25
26 #[inline]
27 pub fn iter(&self) -> core::slice::Iter<CompactString> {
28 self.0.iter()
29 }
30}
31
32impl Deref for CustomSwitch {
33 type Target = InstallerSwitch<2048>;
34
35 #[inline]
36 fn deref(&self) -> &Self::Target {
37 &self.0
38 }
39}
40
41impl DerefMut for CustomSwitch {
42 #[inline]
43 fn deref_mut(&mut self) -> &mut Self::Target {
44 &mut self.0
45 }
46}
47
48impl fmt::Display for CustomSwitch {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 self.0.fmt(f)
51 }
52}
53
54impl FromStr for CustomSwitch {
55 type Err = SwitchError<2048>;
56
57 #[inline]
58 fn from_str(src: &str) -> Result<Self, Self::Err> {
59 InstallerSwitch::<2048>::from_str(src).map(Self)
60 }
61}
62
63impl IntoIterator for CustomSwitch {
64 type Item = CompactString;
65
66 type IntoIter = smallvec::IntoIter<[CompactString; 2]>;
67
68 #[inline]
69 fn into_iter(self) -> Self::IntoIter {
70 self.0.into_iter()
71 }
72}
73
74impl<'switch> IntoIterator for &'switch CustomSwitch {
75 type Item = &'switch CompactString;
76
77 type IntoIter = core::slice::Iter<'switch, CompactString>;
78
79 #[inline]
80 fn into_iter(self) -> Self::IntoIter {
81 self.0.iter()
82 }
83}