Skip to content

Commit 465a25b

Browse files
committed
Apply uglifier
1 parent ffbda8d commit 465a25b

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

src/windows/com.rs

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ use std::time::Duration;
44
use std::{io, ptr};
55

66
use winapi::shared::minwindef::*;
7+
use winapi::shared::ntdef::NULL;
8+
use winapi::shared::winerror::{ERROR_IO_PENDING, ERROR_OPERATION_ABORTED};
79
use winapi::um::commapi::*;
10+
use winapi::um::errhandlingapi::GetLastError;
811
use winapi::um::fileapi::*;
912
use winapi::um::handleapi::*;
13+
use winapi::um::ioapiset::GetOverlappedResult;
14+
use winapi::um::minwinbase::OVERLAPPED;
1015
use winapi::um::processthreadsapi::GetCurrentProcess;
16+
use winapi::um::synchapi::CreateEventW;
1117
use winapi::um::winbase::*;
1218
use winapi::um::winnt::{
1319
DUPLICATE_SAME_ACCESS, FILE_ATTRIBUTE_NORMAL, GENERIC_READ, GENERIC_WRITE, HANDLE,
1420
};
15-
use winapi::shared::winerror::{ERROR_IO_PENDING, ERROR_OPERATION_ABORTED};
16-
use winapi::shared::ntdef::NULL;
17-
use winapi::um::synchapi::CreateEventW;
18-
use winapi::um::minwinbase::OVERLAPPED;
19-
use winapi::um::ioapiset::GetOverlappedResult;
20-
use winapi::um::errhandlingapi::GetLastError;
2121

2222
use crate::windows::dcb;
2323
use crate::{
@@ -32,7 +32,7 @@ impl OverlappedHandle {
3232
fn new() -> io::Result<Self> {
3333
match unsafe { CreateEventW(ptr::null_mut(), TRUE, FALSE, ptr::null_mut()) } {
3434
NULL => Err(io::Error::last_os_error()),
35-
handle => Ok(Self(handle))
35+
handle => Ok(Self(handle)),
3636
}
3737
}
3838

@@ -46,12 +46,9 @@ impl OverlappedHandle {
4646
OVERLAPPED {
4747
Internal: 0,
4848
InternalHigh: 0,
49-
u: unsafe {
50-
MaybeUninit::zeroed().assume_init()
51-
},
49+
u: unsafe { MaybeUninit::zeroed().assume_init() },
5250
hEvent: self.0,
5351
}
54-
5552
}
5653
}
5754

@@ -150,20 +147,28 @@ impl COMPort {
150147
///
151148
/// This function returns an error if the serial port couldn't be cloned.
152149
pub fn try_clone_native(&self) -> Result<COMPort> {
153-
// duplicate communications device handle
154-
let mut duplicate_handle = INVALID_HANDLE_VALUE;
155-
let process = unsafe { GetCurrentProcess() };
156-
let res = unsafe {
157-
DuplicateHandle(process, self.handle, process, &mut duplicate_handle, 0, FALSE, DUPLICATE_SAME_ACCESS)
158-
};
150+
// duplicate communications device handle
151+
let mut duplicate_handle = INVALID_HANDLE_VALUE;
152+
let process = unsafe { GetCurrentProcess() };
153+
let res = unsafe {
154+
DuplicateHandle(
155+
process,
156+
self.handle,
157+
process,
158+
&mut duplicate_handle,
159+
0,
160+
FALSE,
161+
DUPLICATE_SAME_ACCESS,
162+
)
163+
};
159164

160165
match res {
161166
0 => Err(super::error::last_os_error()),
162167
_ => Ok(COMPort {
163168
handle: duplicate_handle,
164169
port_name: self.port_name.clone(),
165170
timeout: self.timeout,
166-
})
171+
}),
167172
}
168173
}
169174

@@ -240,21 +245,25 @@ impl io::Read for COMPort {
240245
)
241246
};
242247
let last_error = unsafe { GetLastError() };
243-
if read_result == 0 && last_error != ERROR_IO_PENDING && last_error != ERROR_OPERATION_ABORTED {
248+
if read_result == 0
249+
&& last_error != ERROR_IO_PENDING
250+
&& last_error != ERROR_OPERATION_ABORTED
251+
{
244252
return Err(io::Error::last_os_error());
245253
}
246-
let overlapped_result = unsafe { GetOverlappedResult(self.handle, &mut overlapped, &mut len, TRUE) };
254+
let overlapped_result =
255+
unsafe { GetOverlappedResult(self.handle, &mut overlapped, &mut len, TRUE) };
247256
evt_handle.close();
248257
let last_error = unsafe { GetLastError() };
249-
if overlapped_result == 0 && last_error != ERROR_OPERATION_ABORTED {
258+
if overlapped_result == 0 && last_error != ERROR_OPERATION_ABORTED {
250259
return Err(io::Error::last_os_error());
251260
}
252261
if len != 0 {
253262
Ok(len as usize)
254263
} else {
255264
Err(io::Error::new(
256-
io::ErrorKind::TimedOut,
257-
"Operation timed out",
265+
io::ErrorKind::TimedOut,
266+
"Operation timed out",
258267
))
259268
}
260269
}
@@ -275,10 +284,14 @@ impl io::Write for COMPort {
275284
)
276285
};
277286
let last_error = unsafe { GetLastError() };
278-
if write_result == 0 && last_error != ERROR_IO_PENDING && last_error != ERROR_OPERATION_ABORTED {
287+
if write_result == 0
288+
&& last_error != ERROR_IO_PENDING
289+
&& last_error != ERROR_OPERATION_ABORTED
290+
{
279291
return Err(io::Error::last_os_error());
280292
}
281-
let overlapped_result = unsafe { GetOverlappedResult(self.handle, &mut overlapped, &mut len, TRUE) };
293+
let overlapped_result =
294+
unsafe { GetOverlappedResult(self.handle, &mut overlapped, &mut len, TRUE) };
282295
evt_handle.close();
283296

284297
let last_error = unsafe { GetLastError() };

0 commit comments

Comments
 (0)