referrerpolicy=no-referrer-when-downgrade

xcm_procedural/
lib.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Procedural macros used in XCM.
18
19use proc_macro::TokenStream;
20use syn::{parse_macro_input, DeriveInput};
21
22mod builder_pattern;
23mod enum_variants;
24mod v3;
25mod v4;
26mod v5;
27mod weight_info;
28
29#[proc_macro_derive(XcmWeightInfoTrait)]
30pub fn derive_xcm_weight_info(item: TokenStream) -> TokenStream {
31	weight_info::derive(item)
32}
33
34#[proc_macro]
35pub fn impl_conversion_functions_for_multilocation_v3(input: TokenStream) -> TokenStream {
36	v3::multilocation::generate_conversion_functions(input)
37		.unwrap_or_else(syn::Error::into_compile_error)
38		.into()
39}
40
41#[proc_macro]
42pub fn impl_conversion_functions_for_junctions_v3(input: TokenStream) -> TokenStream {
43	v3::junctions::generate_conversion_functions(input)
44		.unwrap_or_else(syn::Error::into_compile_error)
45		.into()
46}
47
48#[proc_macro]
49pub fn impl_conversion_functions_for_location_v4(input: TokenStream) -> TokenStream {
50	v4::location::generate_conversion_functions(input)
51		.unwrap_or_else(syn::Error::into_compile_error)
52		.into()
53}
54
55#[proc_macro]
56pub fn impl_conversion_functions_for_junctions_v4(input: TokenStream) -> TokenStream {
57	v4::junctions::generate_conversion_functions(input)
58		.unwrap_or_else(syn::Error::into_compile_error)
59		.into()
60}
61
62#[proc_macro]
63pub fn impl_conversion_functions_for_junctions_v5(input: TokenStream) -> TokenStream {
64	v5::junctions::generate_conversion_functions(input)
65		.unwrap_or_else(syn::Error::into_compile_error)
66		.into()
67}
68
69#[proc_macro]
70pub fn impl_conversion_functions_for_location_v5(input: TokenStream) -> TokenStream {
71	v5::location::generate_conversion_functions(input)
72		.unwrap_or_else(syn::Error::into_compile_error)
73		.into()
74}
75
76/// This is called on the `Instruction` enum, not on the `Xcm` struct,
77/// and allows for the following syntax for building XCMs:
78/// let message = Xcm::builder()
79/// 	.withdraw_asset(assets)
80/// 	.buy_execution(fees, weight_limit)
81/// 	.deposit_asset(assets, beneficiary)
82/// 	.build();
83#[proc_macro_derive(Builder, attributes(builder))]
84pub fn derive_builder(input: TokenStream) -> TokenStream {
85	let input = parse_macro_input!(input as DeriveInput);
86	builder_pattern::derive(input)
87		.unwrap_or_else(syn::Error::into_compile_error)
88		.into()
89}
90
91#[proc_macro_derive(NumVariants)]
92pub fn derive_num_variants(input: TokenStream) -> TokenStream {
93	let input = parse_macro_input!(input as DeriveInput);
94	enum_variants::derive(input)
95		.unwrap_or_else(syn::Error::into_compile_error)
96		.into()
97}