@@ -8,7 +8,7 @@ use core::hash::{Hash, Hasher};
88#[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug , PartialOrd , Ord ) ]
99#[ cfg_attr( feature = "serde1" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
1010
11- pub struct TypeId ( pub ( crate ) u64 ) ;
11+ pub struct TypeId ( pub ( crate ) u128 ) ;
1212
1313impl TypeId {
1414 pub ( crate ) fn of < T : ?Sized + ' static > ( ) -> Self {
@@ -22,21 +22,30 @@ impl TypeId {
2222
2323impl From < core:: any:: TypeId > for TypeId {
2424 fn from ( type_id : core:: any:: TypeId ) -> Self {
25- let mut hasher = TypeIdHasher :: default ( ) ;
25+ match core:: mem:: size_of :: < core:: any:: TypeId > ( ) {
26+ 8 => {
27+ let mut hasher = TypeIdHasher :: default ( ) ;
2628
27- type_id. hash ( & mut hasher) ;
29+ type_id. hash ( & mut hasher) ;
2830
29- TypeId ( hasher. finish ( ) )
31+ TypeId ( hasher. finish ( ) as u128 )
32+ }
33+ 16 => unsafe {
34+ // This is technically unsound, core::any::TypeId has rust layout
35+ // but there is no other way to get the full value anymore
36+
37+ let type_id_ptr: * const core:: any:: TypeId = & type_id;
38+ let type_id_ptr = type_id_ptr as * const TypeId ;
39+ * type_id_ptr
40+ } ,
41+ _ => panic ! ( "Compiler version not supported" ) ,
42+ }
3043 }
3144}
3245
3346impl From < & core:: any:: TypeId > for TypeId {
3447 fn from ( type_id : & core:: any:: TypeId ) -> Self {
35- let mut hasher = TypeIdHasher :: default ( ) ;
36-
37- type_id. hash ( & mut hasher) ;
38-
39- TypeId ( hasher. finish ( ) )
48+ type_id. into ( )
4049 }
4150}
4251
0 commit comments