This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
doc_only.rs
83 lines (76 loc) · 2.58 KB
/
doc_only.rs
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
73
74
75
76
77
78
79
80
81
82
83
// This file is part of Substrate.
// Copyright (C) 2023 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use proc_macro2::Span;
use crate::pallet::Def;
pub fn expand_doc_only(def: &mut Def) -> proc_macro2::TokenStream {
let storage_names = &def.storages.iter().map(|storage| &storage.ident).collect::<Vec<_>>();
let storage_docs = &def.storages.iter().map(|storage| &storage.docs).collect::<Vec<_>>();
let dispatchables = {
if let Some(call_def) = &def.call {
let type_impl_generics = def.type_impl_generics(Span::call_site());
call_def
.methods
.iter()
.map(|method| {
let name = &method.name;
let args = &method
.args
.iter()
.map(|(_, arg_name, arg_type)| quote::quote!( #arg_name: #arg_type, ))
.collect::<proc_macro2::TokenStream>();
let docs = &method.docs;
let line_2 = format!(
" designed to document the [`{}`][`crate::Call::{}`] variant of",
name, name
);
quote::quote!(
#( #[doc = #docs] )*
///
/// ---
///
/// NOTE: This function is an automatically generated, uncallable stub
#[ doc = #line_2 ]
/// the pallet [`Call`](`crate::Call`) enum. You should not attempt to
/// call this function directly.
pub fn #name<#type_impl_generics>(#args) { unreachable!(); }
)
})
.collect::<proc_macro2::TokenStream>()
} else {
quote::quote!()
}
};
quote::quote!(
/// Auto-generated docs-only module listing all defined storage types for this pallet.
/// Note that members of this module cannot be used directly and are only provided for
/// documentation purposes.
#[cfg(doc)]
pub mod storage_types {
use super::*;
#(
#( #[doc = #storage_docs] )*
pub struct #storage_names();
)*
}
/// Auto-generated docs-only module listing all defined dispatchables for this pallet.
/// Note that members of this module cannot be used directly and are only provided for
/// documentation purposes.
#[cfg(doc)]
pub mod dispatchables {
use super::*;
#dispatchables
}
)
}