Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions src/stubwasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use wasmparser::{FuncType, Parser, Payload, TypeRef};

use crate::Library;

pub fn link_stub_modules(
libraries: Vec<Library>,
) -> Result<Option<(Vec<u8>, impl Fn(u32) -> u32)>, Error> {
type LinkedStubModules = Option<(Vec<u8>, Box<dyn Fn(u32) -> u32>)>;

pub fn link_stub_modules(libraries: Vec<Library>) -> Result<LinkedStubModules, Error> {
let mut wasi_imports = HashMap::new();
let mut linker = wit_component::Linker::default()
.validate(true)
Expand Down Expand Up @@ -47,18 +47,21 @@ pub fn link_stub_modules(
let new_adapter_count = u32::try_from(wasi_imports.len())?;
assert!(new_adapter_count >= old_adapter_count);

Ok(Some((component, move |index: u32| {
if index == 0 {
// `main` module
0
} else if index <= new_adapter_count {
// adapter module
old_adapter_count
} else {
// one of the other kinds of module
index + old_adapter_count - new_adapter_count
}
})))
Ok(Some((
component,
Box::new(move |index: u32| {
if index == 0 {
// `main` module
0
} else if index <= new_adapter_count {
// adapter module
old_adapter_count
} else {
// one of the other kinds of module
index + old_adapter_count - new_adapter_count
}
}),
)))
}

fn add_wasi_imports<'a>(
Expand Down
2 changes: 1 addition & 1 deletion src/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub struct MyFunction<'a> {
pub wit_kind: wit_parser::FunctionKind,
}

impl<'a> MyFunction<'a> {
impl MyFunction<'_> {
fn key(&self) -> WorldKey {
if let Some(interface) = self.interface.as_ref() {
WorldKey::Interface(interface.id)
Expand Down
2 changes: 2 additions & 0 deletions src/test/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(non_local_definitions)]

use {
super::{Ctx, Tester, SEED},
anyhow::{anyhow, Error, Result},
Expand Down
Loading