canic_types/
wasm.rs

1//!
2//! Lightweight wrapper for statically embedded WASM modules, providing helper
3//! methods for hashing and metadata used by registry components.
4//!
5
6use crate::utils::wasm::get_wasm_hash;
7
8///
9/// WasmModule
10/// Holds a reference to embedded WASM bytes and exposes helper inspectors.
11///
12
13#[derive(Clone, Debug)]
14pub struct WasmModule {
15    bytes: &'static [u8],
16}
17
18impl WasmModule {
19    #[must_use]
20    pub const fn new(bytes: &'static [u8]) -> Self {
21        Self { bytes }
22    }
23
24    #[must_use]
25    pub fn module_hash(&self) -> Vec<u8> {
26        get_wasm_hash(self.bytes)
27    }
28
29    #[must_use]
30    pub fn to_vec(&self) -> Vec<u8> {
31        self.bytes.to_vec()
32    }
33
34    #[must_use]
35    pub const fn bytes(&self) -> &'static [u8] {
36        self.bytes
37    }
38
39    #[must_use]
40    pub const fn len(&self) -> usize {
41        self.bytes.len()
42    }
43
44    #[must_use]
45    pub const fn is_empty(&self) -> bool {
46        self.bytes.is_empty()
47    }
48}