MCPcopy Index your code
hub / github.com/explodingcamera/tinywasm / new

Method new

crates/tinywasm/src/store/memory/instance.rs:22–43  ·  view source on GitHub ↗
(kind: MemoryType, backend: &MemoryBackend)

Source from the content-addressed store, hash-verified

20 const COPY_CHUNK_SIZE: usize = 4 * 1024;
21
22 pub(crate) fn new(kind: MemoryType, backend: &MemoryBackend) -> Result<Self> {
23 assert!(kind.page_count_initial() <= kind.page_count_max());
24
25 let initial_len = usize::try_from(kind.initial_size())
26 .map_err(|_| Error::UnsupportedFeature("memory size exceeds the host address space"))?;
27
28 crate::log::debug!(
29 "initializing memory with {} pages of {} bytes",
30 kind.page_count_initial(),
31 kind.page_size()
32 );
33
34 let storage = backend.create(kind, initial_len)?;
35 if storage.len() != initial_len {
36 return Err(Error::Other(format!(
37 "memory backend returned {} bytes for a memory that requires {initial_len}",
38 storage.len()
39 )));
40 }
41
42 Ok(Self { kind, inner: storage, page_count: kind.page_count_initial() as usize })
43 }
44
45 pub(crate) fn new_lazy(kind: MemoryType, backend: &MemoryBackend) -> Result<Self> {
46 assert!(kind.page_count_initial() <= kind.page_count_max());

Callers

nothing calls this directly

Calls 4

initial_sizeMethod · 0.80
createMethod · 0.80
page_count_initialMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected