winbrew_models\shared/
deployment.rs1use core::str::FromStr;
2
3use serde::{Deserialize, Serialize};
4
5use super::error::ModelError;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(rename_all = "lowercase")]
10pub enum DeploymentKind {
11 Installed,
13 Portable,
15}
16
17impl DeploymentKind {
18 pub fn as_str(self) -> &'static str {
20 match self {
21 Self::Installed => "installed",
22 Self::Portable => "portable",
23 }
24 }
25}
26
27impl FromStr for DeploymentKind {
28 type Err = ModelError;
29
30 fn from_str(s: &str) -> Result<Self, Self::Err> {
31 match s.trim().to_ascii_lowercase().as_str() {
32 "installed" => Ok(Self::Installed),
33 "portable" => Ok(Self::Portable),
34 other => Err(ModelError::invalid_enum_value("deployment.kind", other)),
35 }
36 }
37}
38
39impl core::fmt::Display for DeploymentKind {
40 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
41 f.write_str(self.as_str())
42 }
43}
44
45impl From<DeploymentKind> for String {
46 fn from(value: DeploymentKind) -> Self {
47 value.to_string()
48 }
49}