wasmer_wasix/runtime/module_cache/
hashed_module.rs1use shared_buffer::OwnedBuffer;
2use wasmer_types::ModuleHash;
3
4use crate::bin_factory::BinaryPackageCommand;
5
6#[derive(Clone, Debug, PartialEq, Eq)]
17pub struct HashedModuleData {
18 hash: ModuleHash,
19 wasm: OwnedBuffer,
20}
21
22impl HashedModuleData {
23 pub fn new(bytes: impl Into<OwnedBuffer>) -> Self {
24 Self::new_sha256(bytes)
25 }
26
27 pub fn new_sha256(bytes: impl Into<OwnedBuffer>) -> Self {
28 let wasm = bytes.into();
29 let hash = ModuleHash::sha256(&wasm);
30 Self { hash, wasm }
31 }
32
33 pub fn new_xxhash(bytes: impl Into<OwnedBuffer>) -> Self {
36 let wasm = bytes.into();
37 let hash = ModuleHash::xxhash(&wasm);
38 Self { hash, wasm }
39 }
40
41 pub fn from_command(command: &BinaryPackageCommand) -> Self {
45 Self {
46 hash: *command.hash(),
47 wasm: command.atom(),
48 }
49 }
50
51 pub fn hash(&self) -> &ModuleHash {
53 &self.hash
54 }
55
56 pub fn wasm(&self) -> &OwnedBuffer {
58 &self.wasm
59 }
60
61 pub fn into_parts(self) -> (ModuleHash, OwnedBuffer) {
62 (self.hash, self.wasm)
63 }
64}