1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi 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
// Tanssi 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 Tanssi.  If not, see <http://www.gnu.org/licenses/>
16

            
17
#[doc(hidden)]
18
pub mod __reexports {
19
    pub use {
20
        frame_support::{CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound},
21
        scale_info::TypeInfo,
22
        sp_core::{Decode, Encode, RuntimeDebug},
23
    };
24
}
25

            
26
pub use macro_rules_attribute::apply;
27

            
28
#[macro_export]
29
macro_rules! derive_storage_traits {
30
    ( $( $tt:tt )* ) => {
31
        #[derive(
32
            $crate::alias::__reexports::RuntimeDebug,
33
            ::core::cmp::PartialEq,
34
            ::core::cmp::Eq,
35
            ::core::clone::Clone,
36
            $crate::alias::__reexports::Encode,
37
            $crate::alias::__reexports::Decode,
38
6790
            $crate::alias::__reexports::TypeInfo,
39
3686
        )]
40
3686
        $($tt)*
41
3686
    }
42
3686
}
43
3686

            
44
3686
// This currently doesn't work due to a quirk in RuntimeDebugNoBound, PartialEqNoBound
45
3686
// and CloneNoBound, as there seem to be something breaking macro hygiene. This is not an
46
3686
// issue when using the derive directly, but doesn't compile when adding it through our macro.
47
3686
// #[macro_export]
48
3686
// macro_rules! derive_storage_traits_no_bounds {
49
3686
//     ( $( $tt:tt )* ) => (
50
3686
//         #[derive(
51
3686
//             $crate::alias::__reexports::RuntimeDebugNoBound,
52
3686
//             $crate::alias::__reexports::PartialEqNoBound,
53
3686
//             $crate::alias::__reexports::EqNoBound,
54
3686
//             $crate::alias::__reexports::CloneNoBound,
55
3686
//             $crate::alias::__reexports::Encode,
56
3686
//             $crate::alias::__reexports::Decode,
57
3686
//             $crate::alias::__reexports::TypeInfo,
58
3686
//         )]
59
3686
//         $($tt)*
60
3686
//     );
61
3686
// }
62
3686

            
63
3686
/// Derives traits related to SCALE encoding and serde.
64
3686
#[macro_export]
65
3686
macro_rules! derive_scale_codec {
66
3686
    ( $( $tt:tt )* ) => {
67
3686
        #[derive(
68
3686
            $crate::alias::__reexports::Encode,
69
3686
            $crate::alias::__reexports::Decode,
70
4268
            $crate::alias::__reexports::TypeInfo,
71
        )]
72
        $($tt)*
73
    }
74
}
75

            
76
macro_rules! trait_alias {
77
    ($vis:vis $alias:ident : $bound0:path $(, $boundN:path)* $(,)?) => {
78
        $vis trait $alias: $bound0 $(+ $boundN)* { }
79
        impl<T: $bound0 $(+ $boundN)*> $alias for T { }
80
    }
81
}
82

            
83
trait_alias!(pub ScaleCodec:
84
    __reexports::Encode,
85
    __reexports::Decode,
86
    __reexports::TypeInfo,
87
);
88

            
89
trait_alias!(pub StorageTraits:
90
    ::core::fmt::Debug,
91
    ::core::clone::Clone,
92
    ::core::cmp::Eq,
93
    ::core::cmp::PartialEq,
94
    ScaleCodec,
95
);