icinga2_api/types/
metadata.rs1use serde::{Deserialize, Serialize};
4
5use super::common::{object::IcingaObject, source_location::IcingaSourceLocation};
6
7#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
9pub enum IcingaMetadataType {
10 UsedBy,
12 Location,
14}
15
16impl std::fmt::Display for IcingaMetadataType {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 match self {
19 IcingaMetadataType::UsedBy => write!(f, "used_by"),
20 IcingaMetadataType::Location => write!(f, "location"),
21 }
22 }
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize, Hash, PartialEq, Eq, PartialOrd, Ord)]
27pub struct IcingaMetadata {
28 pub used_by: Option<Vec<IcingaObject>>,
30 pub location: Option<IcingaSourceLocation>,
32}
33
34pub(crate) fn add_meta_to_url(
36 url: &mut url::Url,
37 meta: &[IcingaMetadataType],
38) -> Result<(), crate::error::Error> {
39 if !meta.is_empty() {
40 for v in meta {
41 url.query_pairs_mut().append_pair("meta", &v.to_string());
42 }
43 }
44 Ok(())
45}