v0.2.0, ran cargo fmt

This commit is contained in:
G2-Games 2024-02-01 16:07:13 -06:00
parent 847367c9a9
commit 138d642fc9
4 changed files with 25 additions and 20 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "cross_usb"
version = "0.1.2"
version = "0.2.0"
authors = ["G2-Games <ke0bhogsg@gmail.com>"]
repository = "https://github.com/G2-Games/cross-usb"
documentation = "https://docs.rs/cross_usb"

View file

@ -54,7 +54,7 @@ pub async fn get_device(vendor_id: u16, product_id: u16) -> Result<UsbDevice, Us
let device = match device_info.open() {
Ok(dev) => 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<UsbDevice, Us
})
}
pub async fn get_device_filter(
device_filter: Vec<DeviceFilter>,
) -> Result<UsbDevice, UsbError> {
pub async fn get_device_filter(device_filter: Vec<DeviceFilter>) -> Result<UsbDevice, UsbError> {
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<usize, UsbError> {

View file

@ -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(&params, array_obj),
)).await {
))
.await
{
Ok(res) => res.into(),
Err(_) => return Err(UsbError::TransferError)
Err(_) => return Err(UsbError::TransferError),
};
Ok(result.bytes_written() as usize)

View file

@ -79,7 +79,7 @@ pub enum UsbError {
#[error("device transfer failed")]
TransferError,
#[error("device communication failed")]
#[error("device communication failed")]
CommunicationError,
#[error("device disconnected")]