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
use super::DeclStorageDefExt;
use proc_macro2::TokenStream;
use quote::quote;
pub fn decl_and_impl(def: &DeclStorageDefExt) -> TokenStream {
let decl_store_items = def.storage_lines.iter().map(|sline| &sline.name).fold(
TokenStream::new(),
|mut items, name| {
items.extend(quote!(type #name;));
items
},
);
let impl_store_items = def.storage_lines.iter().fold(TokenStream::new(), |mut items, line| {
let name = &line.name;
let storage_struct = &line.storage_struct;
items.extend(quote!(type #name = #storage_struct;));
items
});
let visibility = &def.visibility;
let store_trait = &def.store_trait;
let module_struct = &def.module_struct;
let module_impl = &def.module_impl;
let where_clause = &def.where_clause;
quote!(
#visibility trait #store_trait {
#decl_store_items
}
impl #module_impl #store_trait for #module_struct #where_clause {
#impl_store_items
}
)
}