1+ /// Check <https://www.rustwiki.org.cn/en/reference/introduction.html> for help information.
2+
13/// Constructs an event at the trace level.
24#[ allow( unused_macros) ]
35#[ macro_export]
@@ -66,8 +68,8 @@ macro_rules! impl_display_by_debug {
6668 impl $( <$( $generic1 $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ? std:: fmt:: Display
6769 for $struct_name$( <$( $generic1) ,+>) ?
6870 where
69- $( $( $generic2 $( : $trait_tt3 $( + $trait_tt4) * ) ?) ,+, ) ?
7071 $struct_name$( <$( $generic1) ,+>) ?: std:: fmt:: Debug ,
72+ $( $( $generic2 $( : $trait_tt3 $( + $trait_tt4) * ) ?) ,+, ) ?
7173 {
7274 fn fmt( & self , f: & mut std:: fmt:: Formatter <' _>) -> std:: fmt:: Result {
7375 std:: fmt:: Debug :: fmt( self , f)
@@ -83,19 +85,14 @@ macro_rules! impl_display_by_debug {
8385macro_rules! impl_current_for {
8486 (
8587 $name: ident,
86- $struct_name: ident$( <$( $generic1: tt $( : $trait_tt1: tt $( + $trait_tt2: tt) * ) ?) ,+>) ?
87- $( where $(
88- $generic2: tt $( : $trait_tt3: tt $( + $trait_tt4: tt) * ) ?
89- ) ,+) ?
88+ $struct_name: ident$( <$( $generic: tt $( : $trait_tt1: tt $( + $trait_tt2: tt) * ) ?) ,+>) ?
9089 ) => {
9190 thread_local! {
9291 static $name: std:: cell:: RefCell <std:: collections:: VecDeque <* const std:: ffi:: c_void>> =
9392 const { std:: cell:: RefCell :: new( std:: collections:: VecDeque :: new( ) ) } ;
9493 }
9594
96- impl $( <$( $generic1 $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ? $struct_name$( <$( $generic1) ,+>) ?
97- $( where $( $generic2 $( : $trait_tt3 $( + $trait_tt4) * ) ?) ,+) ?
98- {
95+ impl $( <$( $generic $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ? $struct_name$( <$( $generic) ,+>) ? {
9996 /// Init the current.
10097 pub ( crate ) fn init_current( current: & Self ) {
10198 $name. with( |s| {
@@ -154,46 +151,65 @@ macro_rules! impl_current_for {
154151/// Check <https://www.rustwiki.org.cn/en/reference/introduction.html> for help information.
155152#[ macro_export]
156153macro_rules! impl_for_named {
157- ( $struct_name: ident$( <$( $generic1: tt $( : $trait_tt1: tt $( + $trait_tt2: tt) * ) ?) ,+>) ?
158- $( where $(
159- $generic2: tt $( : $trait_tt3: tt $( + $trait_tt4: tt) * ) ?
160- ) ,+) ?
161- ) => {
162- impl $( <$( $generic1 $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ? Eq
163- for $struct_name$( <$( $generic1) ,+>) ?
164- {
165- }
154+ ( $struct_name: ident$( <$( $generic: tt $( : $trait_tt1: tt $( + $trait_tt2: tt) * ) ?) ,+>) ?) => {
155+ $crate:: impl_ord_for_named!( $struct_name$( <$( $generic $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ?) ;
156+ $crate:: impl_hash_for_named!( $struct_name$( <$( $generic $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ?) ;
157+ } ;
158+ }
166159
167- impl $( <$( $generic1 $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ? PartialEq <Self >
168- for $struct_name$( <$( $generic1) ,+>) ?
160+ /// Fast impl `Eq` for `Named` types.
161+ #[ macro_export]
162+ macro_rules! impl_eq_for_named {
163+ ( $struct_name: ident$( <$( $generic: tt $( : $trait_tt1: tt $( + $trait_tt2: tt) * ) ?) ,+>) ?) => {
164+ impl $( <$( $generic $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ? PartialEq <Self >
165+ for $struct_name$( <$( $generic) ,+>) ?
169166 {
170167 fn eq( & self , other: & Self ) -> bool {
171168 self . name( ) . eq( other. name( ) )
172169 }
173170 }
174171
175- impl $( <$( $generic1 $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ? Ord
176- for $struct_name$( <$( $generic1 ) ,+>) ?
172+ impl $( <$( $generic $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ? Eq
173+ for $struct_name$( <$( $generic ) ,+>) ?
177174 {
178- fn cmp( & self , other: & Self ) -> std:: cmp:: Ordering {
179- self . name( ) . cmp( other. name( ) )
180- }
181175 }
176+ } ;
177+ }
182178
183- impl $( <$( $generic1 $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ? PartialOrd <Self >
184- for $struct_name$( <$( $generic1) ,+>) ?
179+ /// Fast impl `Ord` for `Named` types.
180+ #[ macro_export]
181+ macro_rules! impl_ord_for_named {
182+ ( $struct_name: ident$( <$( $generic: tt $( : $trait_tt1: tt $( + $trait_tt2: tt) * ) ?) ,+>) ?) => {
183+ $crate:: impl_eq_for_named!( $struct_name$( <$( $generic $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ?) ;
184+
185+ impl $( <$( $generic $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ? PartialOrd <Self >
186+ for $struct_name$( <$( $generic) ,+>) ?
185187 {
186188 fn partial_cmp( & self , other: & Self ) -> Option <std:: cmp:: Ordering > {
187189 Some ( self . cmp( other) )
188190 }
189191 }
190192
191- impl $( <$( $generic1 $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ? std:: hash:: Hash
192- for $struct_name$( <$( $generic1) ,+>) ?
193+ impl $( <$( $generic $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ? Ord
194+ for $struct_name$( <$( $generic) ,+>) ?
195+ {
196+ fn cmp( & self , other: & Self ) -> std:: cmp:: Ordering {
197+ self . name( ) . cmp( other. name( ) )
198+ }
199+ }
200+ }
201+ }
202+
203+ /// Fast impl `std::hash::Hash` for `Named` types.
204+ #[ macro_export]
205+ macro_rules! impl_hash_for_named {
206+ ( $struct_name: ident$( <$( $generic: tt $( : $trait_tt1: tt $( + $trait_tt2: tt) * ) ?) ,+>) ?) => {
207+ impl $( <$( $generic $( : $trait_tt1 $( + $trait_tt2) * ) ?) ,+>) ? std:: hash:: Hash
208+ for $struct_name$( <$( $generic) ,+>) ?
193209 {
194210 fn hash<H : std:: hash:: Hasher >( & self , state: & mut H ) {
195211 self . name( ) . hash( state)
196212 }
197213 }
198- } ;
214+ }
199215}
0 commit comments