Skip to content

Commit

Permalink
Address clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
paberr committed Nov 29, 2024
1 parent b48d478 commit c4f240f
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 167 deletions.
132 changes: 13 additions & 119 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ members = [".", "proc-macro", "demo", "test"]
description = "Dispatching tasks to a WebWorker without `SharedArrayBuffers`."
authors = ["Pascal Berrang <[email protected]>"]
license = "MIT OR Apache-2.0"
homepage = "https://github.com/paberr/webworker"
repository = "https://github.com/paberr/webworker"
homepage = "https://github.com/paberr/wasmworker"
repository = "https://github.com/paberr/wasmworker"
readme = "README.md"
keywords = ["webworker", "parallelism", "wasm"]

[workspace.dependencies]
webworker = { path = ".", features = ["serde"]}
webworker-proc-macro = { path = "proc-macro" }
wasmworker = { path = ".", features = ["serde"]}
wasmworker-proc-macro = { path = "proc-macro" }

[package]
name = "webworker"
name = "wasmworker"
version = "0.1.0"
edition = "2021"

Expand Down Expand Up @@ -55,10 +55,6 @@ features = [
]
version = "0.3"

[dev-dependencies]
wasm-bindgen-test = "0.3"
webworker-proc-macro = { workspace = true }

[features]
default = []
serde = []
6 changes: 3 additions & 3 deletions demo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "webworker-demo"
name = "wasmworker-demo"
version = "0.1.0"
edition = "2021"
publish = false
Expand All @@ -25,8 +25,8 @@ serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.4", features = ["sync"] }
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
webworker = { workspace = true }
webworker-proc-macro = { workspace = true }
wasmworker = { workspace = true }
wasmworker-proc-macro = { workspace = true }

[dependencies.web-sys]
features = [
Expand Down
4 changes: 2 additions & 2 deletions demo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use send_wrapper::SendWrapper;
use serde::{Deserialize, Serialize};
use tokio::sync::OnceCell;
use wasm_bindgen::{prelude::wasm_bindgen, JsCast, UnwrapThrowExt};
use wasmworker::{iter_ext::IteratorExt, webworker, worker_pool, WebWorker};
use wasmworker_proc_macro::webworker_fn;
use web_sys::{HtmlElement, HtmlInputElement};
use webworker::{iter_ext::IteratorExt, webworker, worker_pool, WebWorker};
use webworker_proc_macro::webworker_fn;

/// A wrapper type to demonstrate serde functionality.
#[derive(Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion proc-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "webworker-proc-macro"
name = "wasmworker-proc-macro"
edition = "2021"

description.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pub fn webworker_fn(_attr: TokenStream, item: TokenStream) -> TokenStream {
const _: () = {
#[wasm_bindgen::prelude::wasm_bindgen]
pub fn #wrapper_fn_name(arg: Box<[u8]>) -> Box<[u8]> {
let arg = webworker::convert::from_bytes(&arg);
let arg = wasmworker::convert::from_bytes(&arg);
let res = super::#fn_name(arg);
let res = webworker::convert::to_bytes(&res);
let res = wasmworker::convert::to_bytes(&res);
res
}
};
Expand Down
6 changes: 1 addition & 5 deletions src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ pub struct WebWorkerFn<T, R> {

impl<T, R> Clone for WebWorkerFn<T, R> {
fn clone(&self) -> Self {
Self {
name: self.name,
_arg: PhantomData,
_res: PhantomData,
}
*self
}
}

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::borrowed_box)]
pub use global::{init_worker_pool, worker_pool};
pub use webworker::WebWorker;

Expand Down
8 changes: 4 additions & 4 deletions src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl WorkerPoolOptions {

impl WorkerPoolOptions {
fn path(&self) -> Option<&str> {
self.path.as_ref().map(String::as_str)
self.path.as_deref()
}

fn strategy(&self) -> Strategy {
Expand Down Expand Up @@ -113,7 +113,7 @@ impl WebWorkerPool {
T: Serialize + for<'de> Deserialize<'de>,
R: Serialize + for<'de> Deserialize<'de>,
{
let worker_id = self.scheduler.schedule(&self);
let worker_id = self.scheduler.schedule(self);
self.workers[worker_id].try_run(func, arg).await
}

Expand All @@ -130,7 +130,7 @@ impl WebWorkerPool {
func: WebWorkerFn<Box<[u8]>, Box<[u8]>>,
arg: &Box<[u8]>,
) -> Result<Box<[u8]>, Full> {
let worker_id = self.scheduler.schedule(&self);
let worker_id = self.scheduler.schedule(self);
self.workers[worker_id].try_run_bytes(func, arg).await
}

Expand All @@ -140,7 +140,7 @@ impl WebWorkerPool {
T: Serialize + for<'de> Deserialize<'de>,
R: Serialize + for<'de> Deserialize<'de>,
{
let worker_id = self.scheduler.schedule(&self);
let worker_id = self.scheduler.schedule(self);
self.workers[worker_id]
.run_internal(func, arg.borrow())
.await
Expand Down
9 changes: 2 additions & 7 deletions src/pool/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ use wasm_bindgen::{prelude::wasm_bindgen, UnwrapThrowExt};
use super::WebWorkerPool;

#[wasm_bindgen]
#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Default, Clone, Copy, PartialEq, Eq)]
pub enum Strategy {
#[default]
RoundRobin,
LoadBased,
}

impl Default for Strategy {
fn default() -> Self {
Strategy::RoundRobin
}
}

pub(super) struct Scheduler {
strategy: Strategy,
current_worker: Cell<usize>,
Expand Down
4 changes: 2 additions & 2 deletions src/webworker/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ impl WebWorker {

let mut wasm_path_owned = None;
let wasm_path = wasm_path.unwrap_or_else(|| {
// TODO: Make nicer
// Calculate path to wasm import.
wasm_path_owned = Some(main_js().as_string().unwrap_throw());
&wasm_path_owned.as_ref().unwrap_throw()
wasm_path_owned.as_ref().unwrap_throw()
});

let code = Array::new();
Expand Down
Loading

0 comments on commit c4f240f

Please sign in to comment.