use shared_buffer::OwnedBuffer;
use wasmer_types::ModuleHash;
use crate::bin_factory::BinaryPackageCommand;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct HashedModuleData {
hash: ModuleHash,
wasm: OwnedBuffer,
}
impl HashedModuleData {
pub fn new(bytes: impl Into<OwnedBuffer>) -> Self {
let wasm = bytes.into();
let hash = ModuleHash::new(&wasm);
Self { hash, wasm }
}
pub fn from_command(command: &BinaryPackageCommand) -> Self {
Self {
hash: *command.hash(),
wasm: command.atom(),
}
}
pub fn hash(&self) -> &ModuleHash {
&self.hash
}
pub fn wasm(&self) -> &OwnedBuffer {
&self.wasm
}
pub fn into_parts(self) -> (ModuleHash, OwnedBuffer) {
(self.hash, self.wasm)
}
}