1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use proc_macro2::Span;
use syn::{Ident, Path};

#[derive(Copy, Clone)]
pub struct AttributeIdent(&'static str);

impl AttributeIdent {
    pub fn as_ident(&self, span: Span) -> Ident {
        Ident::new(self.0, span)
    }
}

pub const NO_SER: AttributeIdent = AttributeIdent("no_ser");
pub const NO_DESER: AttributeIdent = AttributeIdent("no_deser");
pub const ENRICHMENT_TABLE_COMPONENT: AttributeIdent = AttributeIdent("enrichment_table_component");
pub const PROVIDER_COMPONENT: AttributeIdent = AttributeIdent("provider_component");
pub const SECRETS_COMPONENT: AttributeIdent = AttributeIdent("secrets_component");
pub const SINK_COMPONENT: AttributeIdent = AttributeIdent("sink_component");
pub const SOURCE_COMPONENT: AttributeIdent = AttributeIdent("source_component");
pub const TRANSFORM_COMPONENT: AttributeIdent = AttributeIdent("transform_component");

impl PartialEq<AttributeIdent> for Ident {
    fn eq(&self, word: &AttributeIdent) -> bool {
        self == word.0
    }
}

impl<'a> PartialEq<AttributeIdent> for &'a Ident {
    fn eq(&self, word: &AttributeIdent) -> bool {
        *self == word.0
    }
}

impl PartialEq<AttributeIdent> for Path {
    fn eq(&self, word: &AttributeIdent) -> bool {
        self.is_ident(word.0)
    }
}

impl<'a> PartialEq<AttributeIdent> for &'a Path {
    fn eq(&self, word: &AttributeIdent) -> bool {
        self.is_ident(word.0)
    }
}

pub fn path_matches(path: &Path, haystack: &[AttributeIdent]) -> bool {
    haystack.iter().any(|p| path == p)
}