1
1
//! Traits for determining whether we can derive traits for a thing or not.
2
+ //!
3
+ //! These traits tend to come in pairs:
4
+ //!
5
+ //! 1. A "trivial" version, whose implementations aren't allowed to recursively
6
+ //! look at other types or the results of fix point analyses.
7
+ //!
8
+ //! 2. A "normal" version, whose implementations simply query the results of a
9
+ //! fix point analysis.
10
+ //!
11
+ //! The former is used by the analyses when creating the results queried by the
12
+ //! second.
2
13
3
14
use super :: context:: BindgenContext ;
4
15
5
16
/// A trait that encapsulates the logic for whether or not we can derive `Debug`
6
17
/// for a given thing.
7
- ///
8
- /// This should ideally be a no-op that just returns `true`, but instead needs
9
- /// to be a recursive method that checks whether all the proper members can
10
- /// derive debug or not, because of the limit rust has on 32 items as max in the
11
- /// array.
12
18
pub trait CanDeriveDebug {
13
19
/// Return `true` if `Debug` can be derived for this thing, `false`
14
20
/// otherwise.
15
21
fn can_derive_debug ( & self , ctx : & BindgenContext ) -> bool ;
16
22
}
17
23
18
- /// A trait that encapsulates the logic for whether or not we can derive `Debug`.
19
- /// The difference between this trait and the CanDeriveDebug is that the type
20
- /// implementing this trait cannot use recursion or lookup result from fix point
21
- /// analysis. It's a helper trait for fix point analysis.
24
+ /// A trait that encapsulates the logic for whether or not we can trivially
25
+ /// derive `Debug` without looking at any other types or the results of a fix
26
+ /// point analysis. This is a helper trait for the fix point analysis.
22
27
pub trait CanTriviallyDeriveDebug {
23
- /// Return `true` if `Debug` can be derived for this thing, `false`
24
- /// otherwise.
28
+ /// Return `true` if `Debug` can trivially be derived for this thing,
29
+ /// `false` otherwise.
25
30
fn can_trivially_derive_debug ( & self ) -> bool ;
26
31
}
27
32
@@ -33,72 +38,50 @@ pub trait CanDeriveCopy<'a> {
33
38
fn can_derive_copy ( & ' a self , ctx : & ' a BindgenContext ) -> bool ;
34
39
}
35
40
36
- /// A trait that encapsulates the logic for whether or not we can derive `Copy`.
37
- /// The difference between this trait and the CanDeriveCopy is that the type
38
- /// implementing this trait cannot use recursion or lookup result from fix point
39
- /// analysis. It's a helper trait for fix point analysis.
41
+ /// A trait that encapsulates the logic for whether or not we can trivially
42
+ /// derive `Copy` without looking at any other types or results of fix point
43
+ /// analsyses. This is a helper trait for fix point analysis.
40
44
pub trait CanTriviallyDeriveCopy {
41
- /// Return `true` if `Copy` can be derived for this thing, `false`
45
+ /// Return `true` if `Copy` can be trivially derived for this thing, `false`
42
46
/// otherwise.
43
47
fn can_trivially_derive_copy ( & self ) -> bool ;
44
48
}
45
49
46
- /// A trait that encapsulates the logic for whether or not we can derive `Default`
47
- /// for a given thing.
48
- ///
49
- /// This should ideally be a no-op that just returns `true`, but instead needs
50
- /// to be a recursive method that checks whether all the proper members can
51
- /// derive default or not, because of the limit rust has on 32 items as max in the
52
- /// array.
50
+ /// A trait that encapsulates the logic for whether or not we can derive
51
+ /// `Default` for a given thing.
53
52
pub trait CanDeriveDefault {
54
53
/// Return `true` if `Default` can be derived for this thing, `false`
55
54
/// otherwise.
56
55
fn can_derive_default ( & self , ctx : & BindgenContext ) -> bool ;
57
56
}
58
57
59
- /// A trait that encapsulates the logic for whether or not we can derive `Default`.
60
- /// The difference between this trait and the CanDeriveDefault is that the type
61
- /// implementing this trait cannot use recursion or lookup result from fix point
62
- /// analysis. It's a helper trait for fix point analysis.
58
+ /// A trait that encapsulates the logic for whether or not we can trivially
59
+ /// derive `Default` without looking at any other types or results of fix point
60
+ /// analyses. This is a helper trait for the fix point analysis.
63
61
pub trait CanTriviallyDeriveDefault {
64
- /// Return `true` if `Default` can be derived for this thing, `false`
62
+ /// Return `true` if `Default` can trivially derived for this thing, `false`
65
63
/// otherwise.
66
64
fn can_trivially_derive_default ( & self ) -> bool ;
67
65
}
68
66
69
67
/// A trait that encapsulates the logic for whether or not we can derive `Hash`
70
68
/// for a given thing.
71
- ///
72
- /// This should ideally be a no-op that just returns `true`, but instead needs
73
- /// to be a recursive method that checks whether all the proper members can
74
- /// derive default or not, because of the limit rust has on 32 items as max in the
75
- /// array.
76
69
pub trait CanDeriveHash {
77
- /// Return `true` if `Default ` can be derived for this thing, `false`
70
+ /// Return `true` if `Hash ` can be derived for this thing, `false`
78
71
/// otherwise.
79
72
fn can_derive_hash ( & self , ctx : & BindgenContext ) -> bool ;
80
73
}
81
74
82
- /// A trait that encapsulates the logic for whether or not we can derive `PartialEq`
83
- /// for a given thing.
84
- ///
85
- /// This should ideally be a no-op that just returns `true`, but instead needs
86
- /// to be a recursive method that checks whether all the proper members can
87
- /// derive default or not, because of the limit rust has on 32 items as max in the
88
- /// array.
75
+ /// A trait that encapsulates the logic for whether or not we can derive
76
+ /// `PartialEq` for a given thing.
89
77
pub trait CanDerivePartialEq {
90
78
/// Return `true` if `PartialEq` can be derived for this thing, `false`
91
79
/// otherwise.
92
80
fn can_derive_partialeq ( & self , ctx : & BindgenContext ) -> bool ;
93
81
}
94
82
95
- /// A trait that encapsulates the logic for whether or not we can derive `PartialOrd`
96
- /// for a given thing.
97
- ///
98
- /// This should ideally be a no-op that just returns `true`, but instead needs
99
- /// to be a recursive method that checks whether all the proper members can
100
- /// derive partial ord or not, because of the limit rust has on 32 items as max in the
101
- /// array.
83
+ /// A trait that encapsulates the logic for whether or not we can derive
84
+ /// `PartialOrd` for a given thing.
102
85
pub trait CanDerivePartialOrd {
103
86
/// Return `true` if `PartialOrd` can be derived for this thing, `false`
104
87
/// otherwise.
@@ -107,50 +90,32 @@ pub trait CanDerivePartialOrd {
107
90
108
91
/// A trait that encapsulates the logic for whether or not we can derive `Eq`
109
92
/// for a given thing.
110
- ///
111
- /// This should ideally be a no-op that just returns `true`, but instead needs
112
- /// to be a recursive method that checks whether all the proper members can
113
- /// derive eq or not, because of the limit rust has on 32 items as max in the
114
- /// array.
115
93
pub trait CanDeriveEq {
116
-
117
- /// Return `true` if `Eq` can be derived for this thing, `false`
118
- /// otherwise.
119
- fn can_derive_eq ( & self ,
120
- ctx : & BindgenContext )
121
- -> bool ;
94
+ /// Return `true` if `Eq` can be derived for this thing, `false` otherwise.
95
+ fn can_derive_eq ( & self , ctx : & BindgenContext ) -> bool ;
122
96
}
123
97
124
98
/// A trait that encapsulates the logic for whether or not we can derive `Ord`
125
99
/// for a given thing.
126
- ///
127
- /// This should ideally be a no-op that just returns `true`, but instead needs
128
- /// to be a recursive method that checks whether all the proper members can
129
- /// derive ord or not, because of the limit rust has on 32 items as max in the
130
- /// array.
131
100
pub trait CanDeriveOrd {
132
- /// Return `true` if `Ord` can be derived for this thing, `false`
133
- /// otherwise.
101
+ /// Return `true` if `Ord` can be derived for this thing, `false` otherwise.
134
102
fn can_derive_ord ( & self , ctx : & BindgenContext ) -> bool ;
135
103
}
136
104
137
- /// A trait that encapsulates the logic for whether or not we can derive `Hash`.
138
- /// The difference between this trait and the CanDeriveHash is that the type
139
- /// implementing this trait cannot use recursion or lookup result from fix point
140
- /// analysis. It's a helper trait for fix point analysis.
105
+ /// A trait that encapsulates the logic for whether or not we can derive `Hash`
106
+ /// without looking at any other types or the results of any fix point
107
+ /// analyses. This is a helper trait for the fix point analysis.
141
108
pub trait CanTriviallyDeriveHash {
142
- /// Return `true` if `Hash` can be derived for this thing, `false`
109
+ /// Return `true` if `Hash` can trivially be derived for this thing, `false`
143
110
/// otherwise.
144
111
fn can_trivially_derive_hash ( & self ) -> bool ;
145
112
}
146
113
147
- /// A trait that encapsulates the logic for whether or not we can derive
148
- /// `PartialEq` or `PartialOrd`. The difference between this trait and the
149
- /// CanDerivePartialEq is that the type implementing this trait cannot use
150
- /// recursion or lookup result from fix point analysis. It's a helper trait for
151
- /// fix point analysis.
114
+ /// A trait that encapsulates the logic for whether or not we can trivially
115
+ /// derive `PartialEq` or `PartialOrd` without looking at any other types or
116
+ /// results of fix point analyses. This is a helper for the fix point analysis.
152
117
pub trait CanTriviallyDerivePartialEqOrPartialOrd {
153
- /// Return `true` if `PartialEq` or `PartialOrd` can be derived for this
154
- /// thing, `false` otherwise.
118
+ /// Return `true` if `PartialEq` or `PartialOrd` can trivially be derived
119
+ /// for this thing, `false` otherwise.
155
120
fn can_trivially_derive_partialeq_or_partialord ( & self ) -> bool ;
156
121
}
0 commit comments