From 9aa10a019c544afb695ba7ab24acf55d0847340d Mon Sep 17 00:00:00 2001 From: G2-Games Date: Thu, 1 Feb 2024 00:28:46 -0600 Subject: [PATCH] v0.1.2, ran `cargo fmt` --- Cargo.toml | 2 +- src/backend/native.rs | 13 +++++++++---- src/backend/wasm.rs | 28 +++++++++++++++++----------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9552c2b..8ed8fea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cross_usb" -version = "0.1.1" +version = "0.1.2" authors = ["G2-Games "] repository = "https://github.com/G2-Games/cross-usb" documentation = "https://docs.rs/cross_usb" diff --git a/src/backend/native.rs b/src/backend/native.rs index d25092d..c23ed03 100644 --- a/src/backend/native.rs +++ b/src/backend/native.rs @@ -38,22 +38,27 @@ pub async fn get_device(vendor_id: u16, product_id: u16) -> Result) -> Result> { +pub async fn get_device_filter( + device_filter: Vec, +) -> Result> { let devices = nusb::list_devices().unwrap(); let mut device_info = None; for device in devices { - match device_filter.iter().position(|i| i == &FilterTuple(device.vendor_id(), device.product_id())) { + match device_filter + .iter() + .position(|i| i == &FilterTuple(device.vendor_id(), device.product_id())) + { Some(_) => { device_info = Some(device); break; - }, + } None => device_info = None, } } if device_info.is_none() { - return Err("No devices from the list found".into()) + return Err("No devices from the list found".into()); } let device_info = match device_info { diff --git a/src/backend/wasm.rs b/src/backend/wasm.rs index e6b391b..9c301fb 100644 --- a/src/backend/wasm.rs +++ b/src/backend/wasm.rs @@ -29,7 +29,9 @@ pub async fn get_device(vendor_id: u16, product_id: u16) -> Result Result Result Result) -> Result { +pub async fn get_device_filter( + device_filter: Vec, +) -> Result { let window = web_sys::window().unwrap(); let navigator = window.navigator(); let usb = navigator.usb(); - let device_list: Array = JsFuture::from(Promise::resolve(&usb.get_devices())).await?.into(); + let device_list: Array = JsFuture::from(Promise::resolve(&usb.get_devices())) + .await? + .into(); // Check if the device is already paired, if so, we don't need to request it again for js_device in device_list { let device: WasmUsbDevice = js_device.into(); @@ -89,9 +95,7 @@ pub async fn get_device_filter(device_filter: Vec) -> Result) -> Result