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