vector_common/
id.rs

1use std::ops::Deref;
2
3use vector_config::configurable_component;
4
5pub use crate::config::ComponentKey;
6
7/// A list of upstream [source][sources] or [transform][transforms] IDs.
8///
9/// Wildcards (`*`) are supported.
10///
11/// See [configuration][configuration] for more info.
12///
13/// [sources]: https://vector.dev/docs/reference/configuration/sources/
14/// [transforms]: https://vector.dev/docs/reference/configuration/transforms/
15/// [configuration]: https://vector.dev/docs/reference/configuration/
16#[configurable_component]
17#[configurable(metadata(
18    docs::examples = "my-source-or-transform-id",
19    docs::examples = "prefix-*"
20))]
21#[derive(Clone, Debug)]
22pub struct Inputs<T: 'static>(Vec<T>);
23
24impl<T> Inputs<T> {
25    /// Returns `true` if no inputs are present.
26    #[must_use]
27    pub fn is_empty(&self) -> bool {
28        self.0.is_empty()
29    }
30}
31
32impl<T> Deref for Inputs<T> {
33    type Target = [T];
34
35    fn deref(&self) -> &Self::Target {
36        &self.0
37    }
38}
39
40impl<T> Default for Inputs<T> {
41    fn default() -> Self {
42        Self(Vec::new())
43    }
44}
45
46impl<T, U> PartialEq<&[U]> for Inputs<T>
47where
48    T: PartialEq<U>,
49{
50    fn eq(&self, other: &&[U]) -> bool {
51        self.0.as_slice() == &other[..]
52    }
53}
54
55impl<T, U> PartialEq<Vec<U>> for Inputs<T>
56where
57    T: PartialEq<U>,
58{
59    fn eq(&self, other: &Vec<U>) -> bool {
60        &self.0 == other
61    }
62}
63
64impl<T> Extend<T> for Inputs<T> {
65    fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
66        self.0.extend(iter);
67    }
68}
69
70impl<T> IntoIterator for Inputs<T> {
71    type Item = T;
72    type IntoIter = std::vec::IntoIter<T>;
73
74    fn into_iter(self) -> Self::IntoIter {
75        self.0.into_iter()
76    }
77}
78
79impl<'a, T> IntoIterator for &'a Inputs<T> {
80    type Item = &'a T;
81    type IntoIter = std::slice::Iter<'a, T>;
82
83    fn into_iter(self) -> Self::IntoIter {
84        self.0.iter()
85    }
86}
87
88impl<T> FromIterator<T> for Inputs<T> {
89    fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
90        Self(Vec::from_iter(iter))
91    }
92}
93
94impl<T> From<Vec<T>> for Inputs<T> {
95    fn from(inputs: Vec<T>) -> Self {
96        Self(inputs)
97    }
98}