@@ -2,24 +2,22 @@ use core::fmt;
2
2
use std:: {
3
3
any:: { Any , TypeId } ,
4
4
fmt:: Debug ,
5
- hash:: { Hash , Hasher } ,
6
- ops:: DerefMut ,
5
+ hash:: Hash ,
7
6
sync:: Arc ,
8
7
} ;
9
8
10
9
use serde:: { Deserialize , Serialize , de:: DeserializeSeed } ;
10
+ use turbo_dyn_eq_hash:: {
11
+ DynEq , DynHash , DynPartialEq , impl_eq_for_dyn, impl_hash_for_dyn, impl_partial_eq_for_dyn,
12
+ } ;
11
13
12
14
use crate :: trace:: { TraceRawVcs , TraceRawVcsContext } ;
13
15
14
- pub trait MagicAny : mopa:: Any + Send + Sync {
16
+ pub trait MagicAny : mopa:: Any + DynPartialEq + DynEq + DynHash + Send + Sync {
15
17
fn magic_any_arc ( self : Arc < Self > ) -> Arc < dyn Any + Sync + Send > ;
16
18
17
19
fn magic_debug ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result ;
18
20
19
- fn magic_eq ( & self , other : & dyn MagicAny ) -> bool ;
20
-
21
- fn magic_hash ( & self , hasher : & mut dyn Hasher ) ;
22
-
23
21
fn magic_trace_raw_vcs ( & self , trace_context : & mut TraceRawVcsContext ) ;
24
22
25
23
#[ cfg( debug_assertions) ]
@@ -51,17 +49,6 @@ impl<T: Debug + Eq + Hash + Send + Sync + TraceRawVcs + 'static> MagicAny for T
51
49
d. finish ( )
52
50
}
53
51
54
- fn magic_eq ( & self , other : & dyn MagicAny ) -> bool {
55
- match other. downcast_ref :: < Self > ( ) {
56
- None => false ,
57
- Some ( other) => self == other,
58
- }
59
- }
60
-
61
- fn magic_hash ( & self , hasher : & mut dyn Hasher ) {
62
- Hash :: hash ( & ( TypeId :: of :: < Self > ( ) , self ) , & mut HasherMut ( hasher) )
63
- }
64
-
65
52
fn magic_trace_raw_vcs ( & self , trace_context : & mut TraceRawVcsContext ) {
66
53
self . trace_raw_vcs ( trace_context) ;
67
54
}
@@ -78,34 +65,9 @@ impl fmt::Debug for dyn MagicAny {
78
65
}
79
66
}
80
67
81
- impl PartialEq for dyn MagicAny {
82
- fn eq ( & self , other : & Self ) -> bool {
83
- self . magic_eq ( other)
84
- }
85
- }
86
-
87
- impl Eq for dyn MagicAny { }
88
-
89
- impl Hash for dyn MagicAny {
90
- fn hash < H : Hasher > ( & self , hasher : & mut H ) {
91
- self . magic_hash ( hasher)
92
- }
93
- }
94
-
95
- pub struct HasherMut < H : ?Sized > ( pub H ) ;
96
-
97
- impl < H : DerefMut + ?Sized > Hasher for HasherMut < H >
98
- where
99
- H :: Target : Hasher ,
100
- {
101
- fn finish ( & self ) -> u64 {
102
- self . 0 . finish ( )
103
- }
104
-
105
- fn write ( & mut self , bytes : & [ u8 ] ) {
106
- self . 0 . write ( bytes)
107
- }
108
- }
68
+ impl_partial_eq_for_dyn ! ( dyn MagicAny ) ;
69
+ impl_eq_for_dyn ! ( dyn MagicAny ) ;
70
+ impl_hash_for_dyn ! ( dyn MagicAny ) ;
109
71
110
72
impl TraceRawVcs for dyn MagicAny {
111
73
fn trace_raw_vcs ( & self , trace_context : & mut TraceRawVcsContext ) {
0 commit comments