tencent_sdk/services/
common.rs

1use serde::Serialize;
2use std::borrow::Cow;
3
4/// General-purpose Tencent Cloud filter structure.
5///
6/// The platform expects each filter to carry a name and a list of values.
7#[derive(Debug, Clone, Serialize)]
8pub struct Filter<'a> {
9    #[serde(rename = "Name")]
10    pub name: Cow<'a, str>,
11    #[serde(rename = "Values")]
12    pub values: Vec<Cow<'a, str>>,
13}
14
15impl<'a> Filter<'a> {
16    /// Construct a filter from a name and associated values.
17    pub fn new<N, V, I>(name: N, values: I) -> Self
18    where
19        N: Into<Cow<'a, str>>,
20        V: Into<Cow<'a, str>>,
21        I: IntoIterator<Item = V>,
22    {
23        Self {
24            name: name.into(),
25            values: values.into_iter().map(Into::into).collect(),
26        }
27    }
28}
29
30/// Simple key/value tag structure reused across services.
31#[derive(Debug, Clone, Serialize)]
32pub struct Tag<'a> {
33    #[serde(rename = "Key")]
34    pub key: Cow<'a, str>,
35    #[serde(rename = "Value")]
36    pub value: Cow<'a, str>,
37}
38
39impl<'a> Tag<'a> {
40    /// Construct a new tag.
41    pub fn new<K, V>(key: K, value: V) -> Self
42    where
43        K: Into<Cow<'a, str>>,
44        V: Into<Cow<'a, str>>,
45    {
46        Self {
47            key: key.into(),
48            value: value.into(),
49        }
50    }
51}