gent_protocol/
release_channel.rs1use serde::{Deserialize, Serialize};
3use std::{fmt, str::FromStr};
4
5#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
6#[serde(rename_all = "lowercase")]
7pub enum ReleaseChannel {
8 #[default]
9 Stable,
10 Beta,
11}
12
13impl ReleaseChannel {
14 pub fn as_str(self) -> &'static str {
15 match self {
16 Self::Stable => "stable",
17 Self::Beta => "beta",
18 }
19 }
20
21 pub fn is_stable(&self) -> bool {
22 *self == Self::Stable
23 }
24}
25
26impl fmt::Display for ReleaseChannel {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 f.write_str(self.as_str())
29 }
30}
31
32impl FromStr for ReleaseChannel {
33 type Err = &'static str;
34
35 fn from_str(value: &str) -> Result<Self, Self::Err> {
36 match value {
37 "stable" => Ok(Self::Stable),
38 "beta" => Ok(Self::Beta),
39 _ => Err("release channel must be stable or beta"),
40 }
41 }
42}