ink_macro/
error.rs

1// Copyright (C) Use Ink (UK) Ltd.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use proc_macro2::TokenStream as TokenStream2;
16use quote::quote_spanned;
17use syn::spanned::Spanned;
18
19/// Derive error traits depending on the ink! project ABI.
20pub fn derive(attr: TokenStream2, item: TokenStream2) -> TokenStream2 {
21    quote_spanned!(attr.span() =>
22        #[cfg_attr(not(ink_abi = "sol"), ::ink::scale_derive(Encode, Decode, TypeInfo))]
23        #[cfg_attr(
24            any(ink_abi = "sol", ink_abi = "all"),
25            derive(::ink::SolErrorDecode, ::ink::SolErrorEncode)
26        )]
27        #[cfg_attr(
28            all(feature = "std", any(ink_abi = "sol", ink_abi = "all")),
29            derive(::ink::SolErrorMetadata)
30        )]
31        #item
32    )
33}