Skip to content

Commit

Permalink
Add explanation of the hack
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Aug 27, 2024
1 parent 9a4bebe commit 4fbc80b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/cw-schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,17 @@ impl Identifier {
T: ?Sized,
{
// Don't do this at home. I'm a professional.
//
// This is a hack based on the assumption that each type has will produce a unique monomorphized function.
// Therefore each function has a distinct function pointer.
//
// The compiler _might_ break this assumption in the future.
#[inline]
fn type_id_of<T: ?Sized>() -> usize {
type_id_of::<T> as usize
}

debug_assert_eq!(type_id_of::<T>(), type_id_of::<T>());
debug_assert_eq!(core::any::type_name::<T>(), core::any::type_name::<T>());

Self(type_id_of::<T>())
}
Expand Down

0 comments on commit 4fbc80b

Please sign in to comment.