From 925d910ac54b1fa9f9458960cbd99bbdda96b585 Mon Sep 17 00:00:00 2001 From: Chris Nelson Date: Sun, 8 Dec 2024 14:17:56 -0500 Subject: [PATCH] make clippy happy --- .vscode/tasks.json | 26 ++++++++++++++++++++ native/wasmex/src/wit.rs | 33 ++++++++++++++------------ test/component_fixtures/hello_world.ex | 3 ++- test/components/components_test.exs | 9 +++++-- 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 917eb19..ca66246 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -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 + } } ] } \ No newline at end of file diff --git a/native/wasmex/src/wit.rs b/native/wasmex/src/wit.rs index e875ba4..fbdafd5 100644 --- a/native/wasmex/src/wit.rs +++ b/native/wasmex/src/wit.rs @@ -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> { - 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::>(); - Ok(Term::map_from_pairs(env, exported_functions.as_slice()).unwrap()) -} \ No newline at end of file +pub fn exported_functions( + env: rustler::Env, + path: String, + wit: String, +) -> NifResult { + 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::>(); + Ok(Term::map_from_pairs(env, exported_functions.as_slice()).unwrap()) +} diff --git a/test/component_fixtures/hello_world.ex b/test/component_fixtures/hello_world.ex index 637f46f..779a8e5 100644 --- a/test/component_fixtures/hello_world.ex +++ b/test/component_fixtures/hello_world.ex @@ -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 diff --git a/test/components/components_test.exs b/test/components/components_test.exs index db9d152..9a59bd3 100644 --- a/test/components/components_test.exs +++ b/test/components/components_test.exs @@ -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