You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/cw-schema/src/lib.rs
+17-12Lines changed: 17 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ extern crate alloc;
6
6
externcrate std;
7
7
8
8
use alloc::{borrow::Cow, collections::BTreeMap, vec::Vec};
9
-
use core::hash::BuildHasherDefault;
9
+
use core::{any::TypeId,hash::BuildHasherDefault, marker::PhantomData};
10
10
use indexmap::IndexMap;
11
11
use serde::{Deserialize,Serialize};
12
12
use serde_with::skip_serializing_none;
@@ -142,27 +142,32 @@ pub enum Schema {
142
142
}
143
143
144
144
#[derive(Hash,PartialEq,Eq)]
145
-
pubstructIdentifier(usize);
145
+
pubstructIdentifier(TypeId);
146
146
147
147
implIdentifier{
148
148
pubfnof<T>() -> Self
149
149
where
150
150
T: ?Sized,
151
151
{
152
-
// Don't do this at home. I'm a professional.
152
+
// Taken from <sagebind/castaway>: https://github.com/sagebind/castaway/blob/a7baeab32d75d0f105d1415210a2867d213f8818/src/utils.rs#L36
153
153
//
154
-
// This is a hack based on the assumption that each type has will produce a unique monomorphized function.
155
-
// Therefore each function has a distinct function pointer.
156
-
//
157
-
// The compiler _might_ break this assumption in the future.
158
-
#[inline]
159
-
fntype_id_of<T: ?Sized>() -> usize{
160
-
type_id_of::<T>asusize
154
+
// Seems more robust than the previous implementation.
0 commit comments