Skip to content

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
DoumanAsh committed Jun 21, 2022
1 parent bf1edde commit ffbda8d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/windows/dcb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pub(crate) fn get_dcb(handle: HANDLE) -> Result<DCB> {
dcb.DCBlength = std::mem::size_of::<DCB>() as u32;

if unsafe { GetCommState(handle, &mut dcb) } != 0 {
return Ok(dcb);
Ok(dcb)
} else {
return Err(super::error::last_os_error());
Err(super::error::last_os_error())
}
}

Expand Down Expand Up @@ -57,9 +57,9 @@ pub(crate) fn init(dcb: &mut DCB) {

pub(crate) fn set_dcb(handle: HANDLE, mut dcb: DCB) -> Result<()> {
if unsafe { SetCommState(handle, &mut dcb as *mut _) != 0 } {
return Ok(());
Ok(())
} else {
return Err(super::error::last_os_error());
Err(super::error::last_os_error())
}
}

Expand Down
15 changes: 6 additions & 9 deletions src/windows/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ fn get_ports_guids() -> Result<Vec<GUID>> {

// Size vector to hold 1 result (which is the most common result).
let mut num_guids: DWORD = 0;
let mut guids: Vec<GUID> = Vec::new();
guids.push(GUID_NULL); // Placeholder for first result
let mut guids = vec![GUID_NULL]; // Placeholder for first result

// Find out how many GUIDs are associated with "Ports". Initially we assume
// that there is only 1. num_guids will tell us how many there actually are.
Expand Down Expand Up @@ -229,8 +228,8 @@ impl PortDevice {
if let Ok(vid) = u16::from_str_radix(&caps[1], 16) {
if let Ok(pid) = u16::from_str_radix(&caps[2], 16) {
return SerialPortType::UsbPort(UsbPortInfo {
vid: vid,
pid: pid,
vid,
pid,
serial_number: caps.get(4).map(|m| m.as_str().to_string()),
manufacturer: self.property(SPDRP_MFG),
product: self.property(SPDRP_FRIENDLYNAME),
Expand All @@ -257,10 +256,8 @@ impl PortDevice {
ptr::null_mut(),
)
};
if res == FALSE {
if unsafe { GetLastError() } != ERROR_INSUFFICIENT_BUFFER {
return None;
}
if res == FALSE && unsafe { GetLastError() } != ERROR_INSUFFICIENT_BUFFER {
return None;
}
let end_of_buffer = result_buf.len() - 1;
result_buf[end_of_buffer] = 0;
Expand Down Expand Up @@ -292,7 +289,7 @@ pub fn available_ports() -> Result<Vec<SerialPortInfo>> {
}

ports.push(SerialPortInfo {
port_name: port_name,
port_name,
port_type: port_device.port_type(),
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/windows/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use winapi::um::errhandlingapi::GetLastError;
use winapi::um::winbase::{
FormatMessageW, FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_IGNORE_INSERTS,
};
use winapi::um::winnt::{LANG_SYSTEM_DEFAULT, MAKELANGID, SUBLANG_SYS_DEFAULT, WCHAR};
use winapi::um::winnt::{LANG_SYSTEM_DEFAULT, MAKELANGID, SUBLANG_SYS_DEFAULT};

use crate::{Error, ErrorKind};

Expand Down Expand Up @@ -35,7 +35,7 @@ fn error_string(errnum: u32) -> String {
// MAKELANGID(LANG_SYSTEM_DEFAULT, SUBLANG_SYS_DEFAULT)
let langId = MAKELANGID(LANG_SYSTEM_DEFAULT, SUBLANG_SYS_DEFAULT) as DWORD;

let mut buf = [0 as WCHAR; 2048];
let mut buf = [0u16; 2048];

unsafe {
let res = FormatMessageW(
Expand Down

0 comments on commit ffbda8d

Please sign in to comment.