Skip to main content

brooks_lib/cdni/gmd/
spec.rs

1// brooks, Copyright 2026, Will Hawkins
2//
3// This file is part of brooks.
4
5// This file is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18//! Generic metadata definitions
19
20use crate::macros::IntoCdniMetadata;
21
22use serde::{Deserialize, Serialize};
23use serde_json::Value;
24
25use std::fmt::Debug;
26
27impl<A: Debug + Clone + Default, T: IntoCdniMetadata> From<T> for TypedGenericMetadata<A> {
28    fn from(value: T) -> Self {
29        Self {
30            tpe: value.metadata_type(),
31            value: value.metadata_value(),
32            aug: A::default(),
33        }
34    }
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct TypedGenericMetadata<A: Debug + Clone + Default> {
39    #[serde(rename = "generic-metadata-type")]
40    pub tpe: String,
41    #[serde(rename = "generic-metadata-value")]
42    pub value: Value,
43    #[serde(skip)]
44    pub aug: A,
45}
46
47impl<A: Debug + Clone + Default> TypedGenericMetadata<A> {
48    pub fn typed_generic_metadata_name() -> String {
49        "GenericMetadata".to_string()
50    }
51
52    pub fn typed_value<AA: Debug + Default + Clone>(
53        sr: TypedGenericMetadata<AA>,
54    ) -> TypedGenericMetadata<AA> {
55        sr.clone()
56    }
57}