datadog_api_client/datadogV2/model/
model_routing_rule_action.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.
4use serde::{Deserialize, Deserializer, Serialize};
5
6/// Defines an action that is executed when a routing rule matches certain criteria.
7#[non_exhaustive]
8#[derive(Clone, Debug, PartialEq, Serialize)]
9#[serde(untagged)]
10pub enum RoutingRuleAction {
11    SendSlackMessageAction(Box<crate::datadogV2::model::SendSlackMessageAction>),
12    SendTeamsMessageAction(Box<crate::datadogV2::model::SendTeamsMessageAction>),
13    UnparsedObject(crate::datadog::UnparsedObject),
14}
15
16impl<'de> Deserialize<'de> for RoutingRuleAction {
17    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
18    where
19        D: Deserializer<'de>,
20    {
21        let value: serde_json::Value = Deserialize::deserialize(deserializer)?;
22        if let Ok(_v) = serde_json::from_value::<Box<crate::datadogV2::model::SendSlackMessageAction>>(
23            value.clone(),
24        ) {
25            if !_v._unparsed {
26                return Ok(RoutingRuleAction::SendSlackMessageAction(_v));
27            }
28        }
29        if let Ok(_v) = serde_json::from_value::<Box<crate::datadogV2::model::SendTeamsMessageAction>>(
30            value.clone(),
31        ) {
32            if !_v._unparsed {
33                return Ok(RoutingRuleAction::SendTeamsMessageAction(_v));
34            }
35        }
36
37        return Ok(RoutingRuleAction::UnparsedObject(
38            crate::datadog::UnparsedObject { value },
39        ));
40    }
41}