vector_config_macros/
attrs.rs1use proc_macro2::Span;
2use syn::{Ident, Path};
3
4#[derive(Copy, Clone)]
5pub struct AttributeIdent(&'static str);
6
7impl AttributeIdent {
8 pub fn as_ident(&self, span: Span) -> Ident {
9 Ident::new(self.0, span)
10 }
11}
12
13pub const NO_SER: AttributeIdent = AttributeIdent("no_ser");
14pub const NO_DESER: AttributeIdent = AttributeIdent("no_deser");
15pub const API_COMPONENT: AttributeIdent = AttributeIdent("api_component");
16pub const ENRICHMENT_TABLE_COMPONENT: AttributeIdent = AttributeIdent("enrichment_table_component");
17pub const GLOBAL_OPTION_COMPONENT: AttributeIdent = AttributeIdent("global_option_component");
18pub const PROVIDER_COMPONENT: AttributeIdent = AttributeIdent("provider_component");
19pub const SECRETS_COMPONENT: AttributeIdent = AttributeIdent("secrets_component");
20pub const SINK_COMPONENT: AttributeIdent = AttributeIdent("sink_component");
21pub const SOURCE_COMPONENT: AttributeIdent = AttributeIdent("source_component");
22pub const TRANSFORM_COMPONENT: AttributeIdent = AttributeIdent("transform_component");
23
24impl PartialEq<AttributeIdent> for Ident {
25 fn eq(&self, word: &AttributeIdent) -> bool {
26 self == word.0
27 }
28}
29
30impl PartialEq<AttributeIdent> for &Ident {
31 fn eq(&self, word: &AttributeIdent) -> bool {
32 *self == word.0
33 }
34}
35
36impl PartialEq<AttributeIdent> for Path {
37 fn eq(&self, word: &AttributeIdent) -> bool {
38 self.is_ident(word.0)
39 }
40}
41
42impl PartialEq<AttributeIdent> for &Path {
43 fn eq(&self, word: &AttributeIdent) -> bool {
44 self.is_ident(word.0)
45 }
46}
47
48pub fn path_matches(path: &Path, haystack: &[AttributeIdent]) -> bool {
49 haystack.iter().any(|p| path == p)
50}