How is TypeId calculated?


#1

Hi, does anybody know how TypeId is calculated in Rust? Is it stable

  • from build to build of the same project?
  • from version to version of a 3rd party crate?
  • from version to version of rustc?

Thx!


#2

My understanding, which might be somewhat incorrect, is it’s only “reliable” within a compilation session. Put another way, you can’t persist it somewhere and expect future compilations to hash a type to the same id. The docs mention it’s unstable across compiler versions (so it’s a definite “No” to your 3rd bullet point) but don’t say anything beyond that.

You can find the impl inside librustc but it’d be unwise to infer any guarantees from it that aren’t explicitly made.