1 //! Unique IDs for modules in the runtime.
2 
3 use core::num::NonZeroU64;
4 
5 /// A unique identifier (within an engine or similar) for a compiled
6 /// module.
7 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
8 pub struct CompiledModuleId(NonZeroU64);
9 
10 impl CompiledModuleId {
11     /// Allocates a new ID which will be unique within this process.
new() -> Self12     pub fn new() -> Self {
13         // As an implementation detail this is implemented on the same
14         // allocator as stores. It's ok if there are "holes" in the store id
15         // space as it's not required to be compact, it's just used for
16         // uniqueness.
17         CompiledModuleId(crate::store::StoreId::allocate().as_raw())
18     }
19 
20     /// Returns the inner unique integer contained in this ID.
as_u64(self) -> u6421     pub fn as_u64(self) -> u64 {
22         self.0.get()
23     }
24 }
25