datadog_api_client/datadogV2/model/
model_ci_app_pipeline_level.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4
5use serde::{Deserialize, Deserializer, Serialize, Serializer};
6
7#[non_exhaustive]
8#[derive(Clone, Debug, Eq, PartialEq)]
9pub enum CIAppPipelineLevel {
10    PIPELINE,
11    STAGE,
12    JOB,
13    STEP,
14    CUSTOM,
15    UnparsedObject(crate::datadog::UnparsedObject),
16}
17
18impl ToString for CIAppPipelineLevel {
19    fn to_string(&self) -> String {
20        match self {
21            Self::PIPELINE => String::from("pipeline"),
22            Self::STAGE => String::from("stage"),
23            Self::JOB => String::from("job"),
24            Self::STEP => String::from("step"),
25            Self::CUSTOM => String::from("custom"),
26            Self::UnparsedObject(v) => v.value.to_string(),
27        }
28    }
29}
30
31impl Serialize for CIAppPipelineLevel {
32    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
33    where
34        S: Serializer,
35    {
36        match self {
37            Self::UnparsedObject(v) => v.serialize(serializer),
38            _ => serializer.serialize_str(self.to_string().as_str()),
39        }
40    }
41}
42
43impl<'de> Deserialize<'de> for CIAppPipelineLevel {
44    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
45    where
46        D: Deserializer<'de>,
47    {
48        let s: String = String::deserialize(deserializer)?;
49        Ok(match s.as_str() {
50            "pipeline" => Self::PIPELINE,
51            "stage" => Self::STAGE,
52            "job" => Self::JOB,
53            "step" => Self::STEP,
54            "custom" => Self::CUSTOM,
55            _ => Self::UnparsedObject(crate::datadog::UnparsedObject {
56                value: serde_json::Value::String(s.into()),
57            }),
58        })
59    }
60}