From 138d642fc914561f3271650af904f140e3de7b4d Mon Sep 17 00:00:00 2001 From: G2-Games Date: Thu, 1 Feb 2024 16:07:13 -0600 Subject: [PATCH] v0.2.0, ran `cargo fmt` --- Cargo.toml | 2 +- src/backend/native.rs | 25 +++++++++++++------------ src/backend/wasm.rs | 16 ++++++++++------ src/usb.rs | 2 +- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ecb1d08..1b436f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cross_usb" -version = "0.1.2" +version = "0.2.0" 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 aaa331c..9a20beb 100644 --- a/src/backend/native.rs +++ b/src/backend/native.rs @@ -54,7 +54,7 @@ pub async fn get_device(vendor_id: u16, product_id: u16) -> Result dev, - Err(_) => return Err(UsbError::CommunicationError) + Err(_) => return Err(UsbError::CommunicationError), }; Ok(UsbDevice { @@ -63,16 +63,15 @@ 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 prelim_dev_inf in devices { // See if the device exists in the list - if device_filter.iter().position(|info| - { + if device_filter + .iter() + .position(|info| { let mut result = false; if info.vendor_id.is_some() { @@ -96,8 +95,9 @@ pub async fn get_device_filter( } result - } - ).is_some() { + }) + .is_some() + { device_info = Some(prelim_dev_inf) } } @@ -187,10 +187,11 @@ impl<'a> Interface<'a> for UsbInterface { .interface .bulk_in(endpoint, request_buffer) .await - .into_result() { - Ok(res) => Ok(res), - Err(_) => Err(UsbError::TransferError), - } + .into_result() + { + Ok(res) => Ok(res), + Err(_) => Err(UsbError::TransferError), + } } async fn bulk_out(&self, endpoint: u8, data: &[u8]) -> Result { diff --git a/src/backend/wasm.rs b/src/backend/wasm.rs index 8b4f7aa..ddfc326 100644 --- a/src/backend/wasm.rs +++ b/src/backend/wasm.rs @@ -114,8 +114,9 @@ pub async fn get_device_filter( for js_device in device_list { let device: WasmUsbDevice = js_device.into(); - if device_filter.iter().position(|info| - { + if device_filter + .iter() + .position(|info| { let mut result = false; if info.vendor_id.is_some() { @@ -139,8 +140,9 @@ pub async fn get_device_filter( } result - } - ).is_some() { + }) + .is_some() + { return Ok(UsbDevice { device }); } } @@ -292,9 +294,11 @@ impl<'a> Interface<'a> for UsbInterface { &self .device .control_transfer_out_with_buffer_source(¶ms, array_obj), - )).await { + )) + .await + { Ok(res) => res.into(), - Err(_) => return Err(UsbError::TransferError) + Err(_) => return Err(UsbError::TransferError), }; Ok(result.bytes_written() as usize) diff --git a/src/usb.rs b/src/usb.rs index e7d2ef5..e85725d 100644 --- a/src/usb.rs +++ b/src/usb.rs @@ -79,7 +79,7 @@ pub enum UsbError { #[error("device transfer failed")] TransferError, - #[error("device communication failed")] + #[error("device communication failed")] CommunicationError, #[error("device disconnected")]