dis_spawner/
image_pull_policy.rs

1use std::str::FromStr;
2
3use serde::{Serialize, Deserialize};
4
5
6#[derive(Serialize, Deserialize, Clone, Copy)]
7pub enum ImagePullPolicy {
8    Always,
9    Never,
10    IfNotPresent,
11}
12
13impl ToString for ImagePullPolicy {
14    fn to_string(&self) -> String {
15        match self {
16            ImagePullPolicy::Always => "Always",
17            ImagePullPolicy::Never => "Never",
18            ImagePullPolicy::IfNotPresent => "IfNotPresent",
19        }
20        .to_string()
21    }
22}
23
24#[derive(thiserror::Error, Debug)]
25#[error("Unknown ImagePullPolicy: {0}.")]
26pub struct BadPolicyName(String);
27
28impl FromStr for ImagePullPolicy {
29    type Err = BadPolicyName;
30
31    fn from_str(s: &str) -> Result<Self, Self::Err> {
32        match s {
33            "Always" => Ok(ImagePullPolicy::Always),
34            "Never" => Ok(ImagePullPolicy::Never),
35            "IfNotPresent" => Ok(ImagePullPolicy::IfNotPresent),
36            _ => Err(BadPolicyName(s.to_string())),
37        }
38    }
39}