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 v2;
24mod v3;
25mod v4;
26mod weight_info;
27
28#[proc_macro]
29pub fn impl_conversion_functions_for_multilocation_v2(input: TokenStream) -> TokenStream {
30	v2::multilocation::generate_conversion_functions(input)
31		.unwrap_or_else(syn::Error::into_compile_error)
32		.into()
33}
34
35#[proc_macro]
36pub fn impl_conversion_functions_for_junctions_v2(input: TokenStream) -> TokenStream {
37	v2::junctions::generate_conversion_functions(input)
38		.unwrap_or_else(syn::Error::into_compile_error)
39		.into()
40}
41
42#[proc_macro_derive(XcmWeightInfoTrait)]
43pub fn derive_xcm_weight_info(item: TokenStream) -> TokenStream {
44	weight_info::derive(item)
45}
46
47#[proc_macro]
48pub fn impl_conversion_functions_for_multilocation_v3(input: TokenStream) -> TokenStream {
49	v3::multilocation::generate_conversion_functions(input)
50		.unwrap_or_else(syn::Error::into_compile_error)
51		.into()
52}
53
54#[proc_macro]
55pub fn impl_conversion_functions_for_junctions_v3(input: TokenStream) -> TokenStream {
56	v3::junctions::generate_conversion_functions(input)
57		.unwrap_or_else(syn::Error::into_compile_error)
58		.into()
59}
60
61#[proc_macro]
62pub fn impl_conversion_functions_for_location_v4(input: TokenStream) -> TokenStream {
63	v4::location::generate_conversion_functions(input)
64		.unwrap_or_else(syn::Error::into_compile_error)
65		.into()
66}
67
68#[proc_macro]
69pub fn impl_conversion_functions_for_junctions_v4(input: TokenStream) -> TokenStream {
70	v4::junctions::generate_conversion_functions(input)
71		.unwrap_or_else(syn::Error::into_compile_error)
72		.into()
73}
74
75/// This is called on the `Instruction` enum, not on the `Xcm` struct,
76/// and allows for the following syntax for building XCMs:
77/// let message = Xcm::builder()
78/// 	.withdraw_asset(assets)
79/// 	.buy_execution(fees, weight_limit)
80/// 	.deposit_asset(assets, beneficiary)
81/// 	.build();
82#[proc_macro_derive(Builder, attributes(builder))]
83pub fn derive_builder(input: TokenStream) -> TokenStream {
84	let input = parse_macro_input!(input as DeriveInput);
85	builder_pattern::derive(input)
86		.unwrap_or_else(syn::Error::into_compile_error)
87		.into()
88}