diff --git a/src/windows/dcb.rs b/src/windows/dcb.rs index 6af7e493..0b9c60fd 100644 --- a/src/windows/dcb.rs +++ b/src/windows/dcb.rs @@ -11,9 +11,9 @@ pub(crate) fn get_dcb(handle: HANDLE) -> Result { dcb.DCBlength = std::mem::size_of::() 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()) } } @@ -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()) } } diff --git a/src/windows/enumerate.rs b/src/windows/enumerate.rs index 1ebd6eb0..05ecc4ff 100644 --- a/src/windows/enumerate.rs +++ b/src/windows/enumerate.rs @@ -29,8 +29,7 @@ fn get_ports_guids() -> Result> { // Size vector to hold 1 result (which is the most common result). let mut num_guids: DWORD = 0; - let mut guids: Vec = 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. @@ -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), @@ -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; @@ -292,7 +289,7 @@ pub fn available_ports() -> Result> { } ports.push(SerialPortInfo { - port_name: port_name, + port_name, port_type: port_device.port_type(), }); } diff --git a/src/windows/error.rs b/src/windows/error.rs index 72c1f0c6..4ee8b904 100644 --- a/src/windows/error.rs +++ b/src/windows/error.rs @@ -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}; @@ -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(