Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy warnings and add clippy to pipeline #27

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
components: rustfmt, clippy
- name: Check code format
run: cargo fmt -- --check
- name: Check clippy
run: cargo clippy -- --deny warnings
- name: Build
run: cargo build --verbose
- uses: actions-rs/cargo@v1
Expand Down
2 changes: 0 additions & 2 deletions examples/cdc_acm_serial.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use env_logger;
use log::*;
use std::net::*;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use usbip;

#[tokio::main]
async fn main() {
Expand Down
2 changes: 0 additions & 2 deletions examples/hid_keyboard.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use env_logger;
use log::*;
use std::net::*;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use usbip;

#[tokio::main]
async fn main() {
Expand Down
2 changes: 0 additions & 2 deletions examples/host.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use env_logger;
use std::net::*;
use std::sync::Arc;
use std::time::Duration;
use usbip;

#[tokio::main]
async fn main() {
Expand Down
12 changes: 9 additions & 3 deletions src/cdc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ pub struct UsbCdcAcmHandler {
pub tx_buffer: Vec<u8>,
}

impl Default for UsbCdcAcmHandler {
fn default() -> Self {
Self::new()
}
}

/// Sub class code for CDC ACM
pub const CDC_ACM_SUBCLASS: u8 = 0x02;

Expand Down Expand Up @@ -64,7 +70,7 @@ impl UsbInterfaceHandler for UsbCdcAcmHandler {
info!(
"Got bulk out: {:?} \"{}\"",
req,
String::from_utf8_lossy(&req)
String::from_utf8_lossy(req)
);
return Ok(vec![]);
} else {
Expand All @@ -79,7 +85,7 @@ impl UsbInterfaceHandler for UsbCdcAcmHandler {
}

fn get_class_specific_descriptor(&self) -> Vec<u8> {
return vec![
vec![
// Header
0x05, // bFunctionLength
0x24, // CS_INTERFACE
Expand All @@ -90,7 +96,7 @@ impl UsbInterfaceHandler for UsbCdcAcmHandler {
0x24, // CS_INTERFACE
0x02, // ACM
0x00, // Capabilities
];
]
}

fn as_any(&mut self) -> &mut dyn Any {
Expand Down
44 changes: 22 additions & 22 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ impl From<rusbVersion> for Version {
}
}

impl Into<rusbVersion> for Version {
fn into(self) -> rusbVersion {
rusbVersion(self.major, self.minor, self.patch)
impl From<Version> for rusbVersion {
fn from(val: Version) -> Self {
rusbVersion(val.major, val.minor, val.patch)
}
}

Expand Down Expand Up @@ -215,7 +215,7 @@ impl UsbDevice {
intf: Option<&UsbInterface>,
transfer_buffer_length: u32,
setup_packet: SetupPacket,
out_data: &Vec<u8>,
out_data: &[u8],
) -> Result<Vec<u8>> {
use DescriptorType::*;
use Direction::*;
Expand All @@ -238,18 +238,18 @@ impl UsbDevice {
let mut desc = vec![
0x12, // bLength
Device as u8, // bDescriptorType: Device
self.usb_version.minor as u8,
self.usb_version.major as u8, // bcdUSB: USB 2.0
self.device_class, // bDeviceClass
self.device_subclass, // bDeviceSubClass
self.device_protocol, // bDeviceProtocol
self.usb_version.minor,
self.usb_version.major, // bcdUSB: USB 2.0
self.device_class, // bDeviceClass
self.device_subclass, // bDeviceSubClass
self.device_protocol, // bDeviceProtocol
self.ep0_in.max_packet_size as u8, // bMaxPacketSize0
self.vendor_id as u8, // idVendor
self.vendor_id as u8, // idVendor
(self.vendor_id >> 8) as u8,
self.product_id as u8, // idProduct
(self.product_id >> 8) as u8,
self.device_bcd.minor as u8, // bcdDevice
self.device_bcd.major as u8,
self.device_bcd.minor, // bcdDevice
self.device_bcd.major,
self.string_manufacturer, // iManufacturer
self.string_product, // iProduct
self.string_serial, // iSerial
Expand All @@ -260,7 +260,7 @@ impl UsbDevice {
if setup_packet.length < desc.len() as u16 {
desc.resize(setup_packet.length as usize, 0);
}
return Ok(desc);
Ok(desc)
}
Some(BOS) => {
debug!("Get BOS descriptor");
Expand All @@ -275,7 +275,7 @@ impl UsbDevice {
if setup_packet.length < desc.len() as u16 {
desc.resize(setup_packet.length as usize, 0);
}
return Ok(desc);
Ok(desc)
}
Some(Configuration) => {
debug!("Get configuration descriptor");
Expand Down Expand Up @@ -329,7 +329,7 @@ impl UsbDevice {
if setup_packet.length < desc.len() as u16 {
desc.resize(setup_packet.length as usize, 0);
}
return Ok(desc);
Ok(desc)
}
Some(String) => {
debug!("Get string descriptor");
Expand All @@ -346,7 +346,7 @@ impl UsbDevice {
if setup_packet.length < desc.len() as u16 {
desc.resize(setup_packet.length as usize, 0);
}
return Ok(desc);
Ok(desc)
} else {
let s = &self.string_pool[&index];
let bytes: Vec<u16> = s.encode_utf16().collect();
Expand All @@ -363,16 +363,16 @@ impl UsbDevice {
if setup_packet.length < desc.len() as u16 {
desc.resize(setup_packet.length as usize, 0);
}
return Ok(desc);
Ok(desc)
}
}
Some(DeviceQualifier) => {
debug!("Get device qualifier descriptor");
let mut desc = vec![
0x0A, // bLength
DeviceQualifier as u8, // bDescriptorType: Device Qualifier
self.usb_version.minor as u8,
self.usb_version.major as u8,
self.usb_version.minor,
self.usb_version.major,
self.device_class, // bDeviceClass
self.device_subclass, // bDeviceSUbClass
self.device_protocol, // bDeviceProtocol
Expand All @@ -385,11 +385,11 @@ impl UsbDevice {
if setup_packet.length < desc.len() as u16 {
desc.resize(setup_packet.length as usize, 0);
}
return Ok(desc);
Ok(desc)
}
_ => {
warn!("unknown desc type: {:x?}", setup_packet);
return Ok(vec![]);
Ok(vec![])
}
}
}
Expand Down Expand Up @@ -427,7 +427,7 @@ impl UsbDevice {
if setup_packet.length < desc.len() as u16 {
desc.resize(setup_packet.length as usize, 0);
}
return Ok(desc);
Ok(desc)
}
_ if setup_packet.request_type & 0xF == 1 => {
// to interface
Expand Down
4 changes: 2 additions & 2 deletions src/hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl UsbInterfaceHandler for UsbHidKeyboardHandler {
}

fn get_class_specific_descriptor(&self) -> Vec<u8> {
return vec![
vec![
0x09, // bLength
HidDescriptorType::Hid as u8, // bDescriptorType: HID
0x11,
Expand All @@ -145,7 +145,7 @@ impl UsbInterfaceHandler for UsbHidKeyboardHandler {
HidDescriptorType::Report as u8, // bDescriptorType[0] HID
self.report_descriptor.len() as u8,
(self.report_descriptor.len() >> 8) as u8, // wDescriptorLength[0]
];
]
}

fn as_any(&mut self) -> &mut dyn Any {
Expand Down
2 changes: 1 addition & 1 deletion src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl UsbInterfaceHandler for UsbHostInterfaceHandler {
}

fn get_class_specific_descriptor(&self) -> Vec<u8> {
return vec![];
vec![]
}

fn as_any(&mut self) -> &mut dyn Any {
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ mod test {
if result == 0 {
connection.read_exact(&mut vec![0; 0x138]).await.unwrap();
}
return result;
result
}

#[tokio::test]
Expand All @@ -536,7 +536,7 @@ mod test {
// header: 0xC
// device: 0x138
// interface: 4 * 0x1
assert_eq!(mock_socket.output.len(), 0xC + 0x138 + 4 * 0x1);
assert_eq!(mock_socket.output.len(), 0xC + 0x138 + 4);
}

#[tokio::test]
Expand Down Expand Up @@ -694,9 +694,9 @@ mod test {
0x00, 0x00, 0x00, 0x00, // padding
];
connection.write_all(unlink_req.as_slice()).await.unwrap();
connection.read_exact(&mut vec![0; 4 * 5]).await.unwrap();
connection.read_exact(&mut [0; 4 * 5]).await.unwrap();
let result = connection.read_u32().await.unwrap();
connection.read_exact(&mut vec![0; 4 * 6]).await.unwrap();
connection.read_exact(&mut [0; 4 * 6]).await.unwrap();
assert_eq!(result, 0);

let result = attach_device(&mut connection, 0).await;
Expand Down
4 changes: 2 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use super::*;

pub(crate) async fn socket_write_fixed_string<T: AsyncReadExt + AsyncWriteExt + Unpin>(
socket: &mut T,
s: &String,
s: &str,
len: usize,
) -> Result<()> {
let mut path = s.clone().into_bytes();
let mut path = s.as_bytes().to_vec();
assert!(path.len() <= len);
path.resize(len, 0);
socket.write_all(&path).await
Expand Down
Loading