File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -209,9 +209,26 @@ pub(crate) mod _thread {
209209 }
210210
211211 fn thread_to_id ( t : & thread:: Thread ) -> u64 {
212+ use std:: hash:: { Hash , Hasher } ;
213+ struct U64Hash {
214+ v : Option < u64 > ,
215+ }
216+ impl Hasher for U64Hash {
217+ fn write ( & mut self , _: & [ u8 ] ) {
218+ unreachable ! ( )
219+ }
220+ fn write_u64 ( & mut self , i : u64 ) {
221+ self . v = Some ( i) ;
222+ }
223+ fn finish ( & self ) -> u64 {
224+ self . v . expect ( "should have written a u64" )
225+ }
226+ }
212227 // TODO: use id.as_u64() once it's stable, until then, ThreadId is just a wrapper
213- // around NonZeroU64, so this is safe
214- unsafe { std:: mem:: transmute ( t. id ( ) ) }
228+ // around NonZeroU64, so this should work (?)
229+ let mut h = U64Hash { v : None } ;
230+ t. id ( ) . hash ( & mut h) ;
231+ h. finish ( )
215232 }
216233
217234 #[ pyfunction]
You can’t perform that action at this time.
0 commit comments