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

Method create

crates/tinywasm/src/store/memory/mod.rs:310–329  ·  view source on GitHub ↗
(&self, ty: MemoryType, initial_len: usize)

Source from the content-addressed store, hash-verified

308 }
309
310 pub(crate) fn create(&self, ty: MemoryType, initial_len: usize) -> Result<MemoryStorage> {
311 let storage = match &self.kind {
312 MemoryBackendKind::Vec => {
313 Box::new(VecMemory::try_new(initial_len).map_err(Error::Trap)?) as Box<dyn LinearMemory>
314 }
315 MemoryBackendKind::Paged { chunk_size } => {
316 Box::new(PagedMemory::try_new(initial_len, *chunk_size).map_err(Error::Trap)?) as Box<dyn LinearMemory>
317 }
318 MemoryBackendKind::Custom(factory) => factory(ty)?,
319 };
320
321 if storage.len() < initial_len {
322 return Err(Error::Other(format!(
323 "memory backend returned {} bytes for a memory that requires at least {initial_len}",
324 storage.len()
325 )));
326 }
327
328 Ok(MemoryStorage(storage))
329 }
330
331 pub(crate) fn create_lazy(&self, ty: MemoryType, initial_len: usize) -> Result<MemoryStorage> {
332 Ok(MemoryStorage(Box::new(LazyLinearMemory::new_with_initial_len(ty, initial_len, self.clone()))))

Callers 5

open_mode_optionsMethod · 0.80
newMethod · 0.80
ensure_materializedMethod · 0.80
save_csvMethod · 0.80

Calls 2

MemoryStorageClass · 0.85
lenMethod · 0.45

Tested by 1

save_csvMethod · 0.64