Skip to content

Commit

Permalink
make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Nelson committed Dec 8, 2024
1 parent b50947c commit 925d910
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
26 changes: 26 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,32 @@
"kind": "build",
"isDefault": true
}
},
{
"label": "rust clippy",
"type": "process",
"command": "cargo",
"args": [
"clippy",
"--all-targets",
"--all-features",
"--",
"-D",
"warnings",
"-A",
"clippy::extra_unused_lifetimes"
],
"options": {
"cwd": "${workspaceRoot}/native/wasmex"
},
"problemMatcher": [
"$mixCompileWarning",
"$mixCompileError"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
33 changes: 18 additions & 15 deletions native/wasmex/src/wit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ use rustler::{NifResult, Term};
use wit_parser::{Resolve, WorldItem};

#[rustler::nif(name = "wit_exported_functions")]
pub fn exported_functions<'a>(env: rustler::Env<'a>, path: String, wit: String) -> NifResult<Term<'a>> {
let mut resolve = Resolve::new();
let id = resolve.push_str(path, &wit).unwrap();
let world_id = resolve.select_world(id, None).unwrap();
let exports = &resolve.worlds[world_id].exports;
let exported_functions = exports.iter().filter_map(|(_key, value)|
match value {
WorldItem::Function(function) => {
Some((&function.name, function.params.len()))
}
_ => None
}
).collect::<Vec<(&String, usize)>>();
Ok(Term::map_from_pairs(env, exported_functions.as_slice()).unwrap())
}
pub fn exported_functions(
env: rustler::Env,
path: String,
wit: String,
) -> NifResult<Term> {
let mut resolve = Resolve::new();
let id = resolve.push_str(path, &wit).unwrap();
let world_id = resolve.select_world(id, None).unwrap();
let exports = &resolve.worlds[world_id].exports;
let exported_functions = exports
.iter()
.filter_map(|(_key, value)| match value {
WorldItem::Function(function) => Some((&function.name, function.params.len())),
_ => None,
})
.collect::<Vec<(&String, usize)>>();
Ok(Term::map_from_pairs(env, exported_functions.as_slice()).unwrap())
}
3 changes: 2 additions & 1 deletion test/component_fixtures/hello_world.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule HelloWorld do
use Wasmex.Components.Component, wit: "test/component_fixtures/hello_world/hello-world.wit"
@moduledoc false

use Wasmex.Components.Component, wit: "test/component_fixtures/hello_world/hello-world.wit"
end
9 changes: 7 additions & 2 deletions test/components/components_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ defmodule Wasmex.ComponentsTest do

test "using the component macro" do
component_bytes = File.read!("test/component_fixtures/hello_world/hello_world.wasm")
component_pid = start_supervised!({HelloWorld, %{bytes: component_bytes, wasi: %WasiP2Options{}}})

component_pid =
start_supervised!({HelloWorld, %{bytes: component_bytes, wasi: %WasiP2Options{}}})

assert {:ok, "Hello, Elixir!"} = HelloWorld.greet(component_pid, "Elixir")
assert {:ok, ["Hello, Elixir!", "Hello, Elixir!"]} = HelloWorld.multi_greet(component_pid, "Elixir", 2)

assert {:ok, ["Hello, Elixir!", "Hello, Elixir!"]} =
HelloWorld.multi_greet(component_pid, "Elixir", 2)
end

test "wasi interaction" do
Expand Down

0 comments on commit 925d910

Please sign in to comment.