wasmtime/runtime/vm/
module_id.rs

1//! Unique IDs for modules in the runtime.
2
3use 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)]
8pub struct CompiledModuleId(NonZeroU64);
9
10impl CompiledModuleId {
11    /// Allocates a new ID which will be unique within this process.
12    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}