pub struct Module(/* private fields */);Expand description
A compiled module handle.
Implementations§
Source§impl Module
impl Module
Sourcepub fn from_bytes(
bytes: &[u8],
identifier: Option<&[u8]>,
) -> Result<(Self, CompileStatus), ModuleError>
pub fn from_bytes( bytes: &[u8], identifier: Option<&[u8]>, ) -> Result<(Self, CompileStatus), ModuleError>
Compile a module from raw bytes.
If identifier is Some and a module is already cached under it, no compilation
occurs and CompileStatus::Cached is returned. Otherwise the bytes are compiled,
cached under identifier if supplied, and CompileStatus::Compiled is returned.
A Cached result means the call was cheap; a Compiled result means real work was
done. Callers should weight accordingly.
Sourcepub fn lookup(identifier: &[u8]) -> Result<Self, ModuleError>
pub fn lookup(identifier: &[u8]) -> Result<Self, ModuleError>
Look up a previously compiled module by identifier.
Returns Err(ModuleError::NotCached) if no module is cached under identifier.
This is a pure cache lookup — no storage access, no compilation — so the call is
cheap and never reads from the trie. Use Module::from_storage_key if you want
the host to fall back to a storage read on miss.
Sourcepub fn from_storage_key(
storage_key: &[u8],
child_trie: &[u8],
) -> Result<(Self, CompileStatus), ModuleError>
pub fn from_storage_key( storage_key: &[u8], child_trie: &[u8], ) -> Result<(Self, CompileStatus), ModuleError>
Compile (or fetch from cache) a module whose program bytes live at storage_key.
The storage_key is also used as the cache identifier. Pass an empty child_trie to
read from the main state trie. On a cache hit returns CompileStatus::Cached
(cheap); on a miss the host reads from storage and compiles, returning
CompileStatus::Compiled.