1- use rspack_cacheable:: { cacheable, from_bytes, to_bytes} ;
1+ use rspack_cacheable:: { cacheable, from_bytes, r#dyn :: VTablePtr , to_bytes} ;
22
33#[ test]
44#[ cfg_attr( miri, ignore) ]
@@ -99,7 +99,7 @@ fn test_manual_cacheable_dyn_macro() {
9999 value : * const Self ,
100100 context : & mut Validator ,
101101 ) -> Result < ( ) , DeserializeError > {
102- let vtable: usize = std :: mem :: transmute ( ptr_meta:: metadata ( value) ) ;
102+ let vtable = VTablePtr :: new ( ptr_meta:: metadata ( value) ) ;
103103 if let Some ( check_bytes_dyn) = CHECK_BYTES_REGISTRY . get ( & vtable) {
104104 check_bytes_dyn ( value. cast ( ) , context) ?;
105105 Ok ( ( ) )
@@ -115,13 +115,8 @@ fn test_manual_cacheable_dyn_macro() {
115115 color : String ,
116116 }
117117
118- static __DYN_ID_DOG_ANIMAL: std:: sync:: LazyLock < u64 > = std:: sync:: LazyLock :: new ( || {
119- use std:: hash:: { DefaultHasher , Hash , Hasher } ;
120- let mut hasher = DefaultHasher :: new ( ) ;
121- module_path ! ( ) . hash ( & mut hasher) ;
122- line ! ( ) . hash ( & mut hasher) ;
123- hasher. finish ( )
124- } ) ;
118+ const __DYN_ID_DOG_ANIMAL: u64 =
119+ xxhash_rust:: const_xxh64:: xxh64 ( concat ! ( module_path!( ) , ":" , line!( ) ) . as_bytes ( ) , 0 ) ;
125120
126121 impl Animal for Dog {
127122 fn color ( & self ) -> & str {
@@ -132,7 +127,7 @@ fn test_manual_cacheable_dyn_macro() {
132127 }
133128
134129 fn __dyn_id ( & self ) -> u64 {
135- * __DYN_ID_DOG_ANIMAL
130+ __DYN_ID_DOG_ANIMAL
136131 }
137132 }
138133
@@ -149,14 +144,12 @@ fn test_manual_cacheable_dyn_macro() {
149144 DeserializeError , Deserializer ,
150145 } ;
151146
152- fn get_vtable ( ) -> usize {
153- unsafe {
154- core:: mem:: transmute ( ptr_meta:: metadata (
155- core:: ptr:: null :: < Archived < Dog > > ( ) as * const <dyn Animal as ArchiveUnsized >:: Archived
156- ) )
157- }
147+ const fn get_vtable ( ) -> VTablePtr {
148+ VTablePtr :: new ( ptr_meta:: metadata (
149+ core:: ptr:: null :: < Archived < Dog > > ( ) as * const <dyn Animal as ArchiveUnsized >:: Archived
150+ ) )
158151 }
159- inventory:: submit! { DynEntry :: new( * __DYN_ID_DOG_ANIMAL, get_vtable( ) ) }
152+ inventory:: submit! { DynEntry :: new( __DYN_ID_DOG_ANIMAL, get_vtable( ) ) }
160153 inventory:: submit! { CheckBytesEntry :: new( get_vtable( ) , default_check_bytes_dyn:: <Archived <Dog >>) }
161154
162155 impl DeserializeDyn < dyn Animal > for ArchivedDog
@@ -184,13 +177,8 @@ fn test_manual_cacheable_dyn_macro() {
184177 color : String ,
185178 }
186179
187- static __DYN_ID_CAT_ANIMAL: std:: sync:: LazyLock < u64 > = std:: sync:: LazyLock :: new ( || {
188- use std:: hash:: { DefaultHasher , Hash , Hasher } ;
189- let mut hasher = DefaultHasher :: new ( ) ;
190- module_path ! ( ) . hash ( & mut hasher) ;
191- line ! ( ) . hash ( & mut hasher) ;
192- hasher. finish ( )
193- } ) ;
180+ const __DYN_ID_CAT_ANIMAL: u64 =
181+ xxhash_rust:: const_xxh64:: xxh64 ( concat ! ( module_path!( ) , ":" , line!( ) ) . as_bytes ( ) , 0 ) ;
194182
195183 impl Animal for Cat {
196184 fn color ( & self ) -> & str {
@@ -201,7 +189,7 @@ fn test_manual_cacheable_dyn_macro() {
201189 }
202190
203191 fn __dyn_id ( & self ) -> u64 {
204- * __DYN_ID_CAT_ANIMAL
192+ __DYN_ID_CAT_ANIMAL
205193 }
206194 }
207195
@@ -218,14 +206,12 @@ fn test_manual_cacheable_dyn_macro() {
218206 DeserializeError , Deserializer ,
219207 } ;
220208
221- fn get_vtable ( ) -> usize {
222- unsafe {
223- core:: mem:: transmute ( ptr_meta:: metadata (
224- core:: ptr:: null :: < Archived < Cat > > ( ) as * const <dyn Animal as ArchiveUnsized >:: Archived
225- ) )
226- }
209+ const fn get_vtable ( ) -> VTablePtr {
210+ VTablePtr :: new ( ptr_meta:: metadata (
211+ core:: ptr:: null :: < Archived < Cat > > ( ) as * const <dyn Animal as ArchiveUnsized >:: Archived
212+ ) )
227213 }
228- inventory:: submit! { DynEntry :: new( * __DYN_ID_CAT_ANIMAL, get_vtable( ) ) }
214+ inventory:: submit! { DynEntry :: new( __DYN_ID_CAT_ANIMAL, get_vtable( ) ) }
229215 inventory:: submit! { CheckBytesEntry :: new( get_vtable( ) , default_check_bytes_dyn:: <Archived <Cat >>) }
230216
231217 impl DeserializeDyn < dyn Animal > for ArchivedCat
0 commit comments