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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
mod config;
mod item;
#[cfg(test)]
mod tests;
pub use self::{
config::TraitDefinitionConfig,
item::{
InkItemTrait,
InkTraitItem,
InkTraitMessage,
IterInkTraitItems,
},
};
use super::attrs::InkAttribute;
use proc_macro2::TokenStream as TokenStream2;
use syn::Result;
#[derive(Debug, PartialEq, Eq)]
pub struct InkTraitDefinition {
config: TraitDefinitionConfig,
item: InkItemTrait,
}
impl InkTraitDefinition {
pub fn new(config: TokenStream2, input: TokenStream2) -> Result<Self> {
let parsed_config = syn::parse2::<crate::ast::AttributeArgs>(config)?;
let parsed_item = syn::parse2::<syn::ItemTrait>(input)?;
let config = TraitDefinitionConfig::try_from(parsed_config)?;
let item = InkItemTrait::new(&config, parsed_item)?;
Ok(Self { config, item })
}
#[cfg(test)]
pub fn from_raw_parts(config: TraitDefinitionConfig, item: InkItemTrait) -> Self {
Self { config, item }
}
}
impl InkTraitDefinition {
pub fn config(&self) -> &TraitDefinitionConfig {
&self.config
}
pub fn item(&self) -> &InkItemTrait {
&self.item
}
}