Skip to content

Commit 959d1a9

Browse files
committed
fix clippy
1 parent f167a66 commit 959d1a9

File tree

15 files changed

+76
-124
lines changed

15 files changed

+76
-124
lines changed

core/src/co_pool/mod.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,7 @@ impl<'p> CoroutinePool<'p> {
221221
match self.state() {
222222
PoolState::Running => {}
223223
PoolState::Stopping | PoolState::Stopped => {
224-
return Err(Error::new(
225-
ErrorKind::Other,
226-
"The coroutine pool is stopping or stopped !",
227-
))
224+
return Err(Error::other("The coroutine pool is stopping or stopped !"))
228225
}
229226
}
230227
let name = name.unwrap_or(format!("{}@{}", self.name(), uuid::Uuid::new_v4()));
@@ -292,12 +289,11 @@ impl<'p> CoroutinePool<'p> {
292289
let (lock, cvar) = &*arc;
293290
drop(
294291
cvar.wait_timeout_while(
295-
lock.lock()
296-
.map_err(|e| Error::new(ErrorKind::Other, format!("{e}")))?,
292+
lock.lock().map_err(|e| Error::other(format!("{e}")))?,
297293
wait_time,
298294
|&mut pending| pending,
299295
)
300-
.map_err(|e| Error::new(ErrorKind::Other, format!("{e}")))?,
296+
.map_err(|e| Error::other(format!("{e}")))?,
301297
);
302298
if let Some(r) = self.try_take_task_result(key) {
303299
self.notify(key);
@@ -372,8 +368,7 @@ impl<'p> CoroutinePool<'p> {
372368
"The coroutine pool:{} has reached its maximum size !",
373369
self.name()
374370
);
375-
return Err(Error::new(
376-
ErrorKind::Other,
371+
return Err(Error::other(
377372
"The coroutine pool has reached its maximum size !",
378373
));
379374
}
@@ -447,12 +442,7 @@ impl<'p> CoroutinePool<'p> {
447442
PoolState::Running | PoolState::Stopping => {
448443
drop(self.try_grow());
449444
}
450-
PoolState::Stopped => {
451-
return Err(Error::new(
452-
ErrorKind::Other,
453-
"The coroutine pool is stopped !",
454-
))
455-
}
445+
PoolState::Stopped => return Err(Error::other("The coroutine pool is stopped !")),
456446
}
457447
Self::init_current(self);
458448
let r = self.try_timeout_schedule(timeout_time);

core/src/co_pool/state.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::co_pool::CoroutinePool;
22
use crate::common::constants::PoolState;
3-
use std::io::{Error, ErrorKind};
3+
use std::io::Error;
44

55
impl CoroutinePool<'_> {
66
/// running -> stopping
@@ -37,10 +37,11 @@ impl CoroutinePool<'_> {
3737
assert_eq!(old_state, self.state.replace(new_state));
3838
return Ok(old_state);
3939
}
40-
Err(Error::new(
41-
ErrorKind::Other,
42-
format!("{} unexpected {current}->{:?}", self.name(), new_state),
43-
))
40+
Err(Error::other(format!(
41+
"{} unexpected {current}->{:?}",
42+
self.name(),
43+
new_state
44+
)))
4445
}
4546
}
4647

core/src/coroutine/korosensei.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::cell::{Cell, RefCell, UnsafeCell};
1111
use std::collections::VecDeque;
1212
use std::ffi::c_longlong;
1313
use std::fmt::Debug;
14-
use std::io::{Error, ErrorKind};
14+
use std::io::Error;
1515

1616
cfg_if::cfg_if! {
1717
if #[cfg(unix)] {
@@ -452,10 +452,10 @@ where
452452
CoroutineState::Syscall(y, syscall, state) => {
453453
Ok(CoroutineState::Syscall(y, syscall, state))
454454
}
455-
_ => Err(Error::new(
456-
ErrorKind::Other,
457-
format!("{} unexpected state {current}", self.name()),
458-
)),
455+
_ => Err(Error::other(format!(
456+
"{} unexpected state {current}",
457+
self.name()
458+
))),
459459
}
460460
}
461461
CoroutineResult::Return(result) => {

core/src/coroutine/state.rs

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::coroutine::listener::Listener;
44
use crate::coroutine::Coroutine;
55
use crate::{error, info};
66
use std::fmt::Debug;
7-
use std::io::{Error, ErrorKind};
7+
use std::io::Error;
88

99
impl<Param, Yield, Return> Coroutine<'_, Param, Yield, Return>
1010
where
@@ -45,14 +45,11 @@ where
4545
}
4646
_ => {}
4747
}
48-
Err(Error::new(
49-
ErrorKind::Other,
50-
format!(
51-
"{} unexpected {current}->{:?}",
52-
self.name(),
53-
CoroutineState::<Yield, Return>::Ready
54-
),
55-
))
48+
Err(Error::other(format!(
49+
"{} unexpected {current}->{:?}",
50+
self.name(),
51+
CoroutineState::<Yield, Return>::Ready
52+
)))
5653
}
5754

5855
/// ready -> running
@@ -87,14 +84,11 @@ where
8784
}
8885
_ => {}
8986
}
90-
Err(Error::new(
91-
ErrorKind::Other,
92-
format!(
93-
"{} unexpected {current}->{:?}",
94-
self.name(),
95-
CoroutineState::<Yield, Return>::Running
96-
),
97-
))
87+
Err(Error::other(format!(
88+
"{} unexpected {current}->{:?}",
89+
self.name(),
90+
CoroutineState::<Yield, Return>::Running
91+
)))
9892
}
9993

10094
/// running -> suspend
@@ -109,14 +103,11 @@ where
109103
self.on_suspend(self, old_state);
110104
return Ok(());
111105
}
112-
Err(Error::new(
113-
ErrorKind::Other,
114-
format!(
115-
"{} unexpected {current}->{:?}",
116-
self.name(),
117-
CoroutineState::<Yield, Return>::Suspend(val, timestamp)
118-
),
119-
))
106+
Err(Error::other(format!(
107+
"{} unexpected {current}->{:?}",
108+
self.name(),
109+
CoroutineState::<Yield, Return>::Suspend(val, timestamp)
110+
)))
120111
}
121112

122113
/// running -> syscall
@@ -148,14 +139,11 @@ where
148139
}
149140
_ => {}
150141
}
151-
Err(Error::new(
152-
ErrorKind::Other,
153-
format!(
154-
"{} unexpected {current}->{:?}",
155-
self.name(),
156-
CoroutineState::<Yield, Return>::Syscall(val, syscall, syscall_state)
157-
),
158-
))
142+
Err(Error::other(format!(
143+
"{} unexpected {current}->{:?}",
144+
self.name(),
145+
CoroutineState::<Yield, Return>::Syscall(val, syscall, syscall_state)
146+
)))
159147
}
160148

161149
/// running -> complete
@@ -170,14 +158,11 @@ where
170158
self.on_complete(self, old_state, val);
171159
return Ok(());
172160
}
173-
Err(Error::new(
174-
ErrorKind::Other,
175-
format!(
176-
"{} unexpected {current}->{:?}",
177-
self.name(),
178-
CoroutineState::<Yield, Return>::Complete(val)
179-
),
180-
))
161+
Err(Error::other(format!(
162+
"{} unexpected {current}->{:?}",
163+
self.name(),
164+
CoroutineState::<Yield, Return>::Complete(val)
165+
)))
181166
}
182167

183168
/// running -> error
@@ -192,14 +177,11 @@ where
192177
self.on_error(self, old_state, msg);
193178
return Ok(());
194179
}
195-
Err(Error::new(
196-
ErrorKind::Other,
197-
format!(
198-
"{} unexpected {current}->{:?}",
199-
self.name(),
200-
CoroutineState::<Yield, Return>::Error(msg)
201-
),
202-
))
180+
Err(Error::other(format!(
181+
"{} unexpected {current}->{:?}",
182+
self.name(),
183+
CoroutineState::<Yield, Return>::Error(msg)
184+
)))
203185
}
204186
}
205187

core/src/net/operator/windows/mod.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl<'o> Operator<'o> {
239239
&mut sock_info_len,
240240
) != 0
241241
{
242-
return Err(Error::new(ErrorKind::Other, "get socket info failed"));
242+
return Err(Error::other("get socket info failed"));
243243
}
244244
self.add_handle(fd as HANDLE)?;
245245
let socket = WSASocketW(
@@ -251,10 +251,7 @@ impl<'o> Operator<'o> {
251251
WSA_FLAG_OVERLAPPED,
252252
);
253253
if INVALID_SOCKET == socket {
254-
return Err(Error::new(
255-
ErrorKind::Other,
256-
format!("add {syscall_name} operation failed"),
257-
));
254+
return Err(Error::other(format!("add {syscall_name} operation failed")));
258255
}
259256
let size = size_of::<SOCKADDR_IN>()
260257
.saturating_add(16)
@@ -370,10 +367,9 @@ impl<'o> Operator<'o> {
370367
{
371368
let errno = WSAGetLastError();
372369
if WSA_IO_PENDING != errno {
373-
return Err(Error::new(
374-
ErrorKind::Other,
375-
format!("add {syscall_name} operation failed with {errno}"),
376-
));
370+
return Err(Error::other(format!(
371+
"add {syscall_name} operation failed with {errno}"
372+
)));
377373
}
378374
}
379375
eprintln!("add {syscall_name} operation:{overlapped}");
@@ -464,10 +460,9 @@ impl<'o> Operator<'o> {
464460
{
465461
let errno = WSAGetLastError();
466462
if WSA_IO_PENDING != errno {
467-
return Err(Error::new(
468-
ErrorKind::Other,
469-
format!("add {syscall_name} operation failed with {errno}"),
470-
));
463+
return Err(Error::other(format!(
464+
"add {syscall_name} operation failed with {errno}"
465+
)));
471466
}
472467
}
473468
eprintln!("add {syscall_name} operation:{overlapped}");

core/src/scheduler.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{co, impl_current_for, impl_display_by_debug, impl_for_named};
99
use dashmap::DashMap;
1010
use std::collections::{BinaryHeap, HashMap, VecDeque};
1111
use std::ffi::c_longlong;
12-
use std::io::{Error, ErrorKind};
12+
use std::io::Error;
1313
use std::sync::atomic::{AtomicUsize, Ordering};
1414
use std::time::Duration;
1515

@@ -318,8 +318,7 @@ impl<'s> Scheduler<'s> {
318318
);
319319
}
320320
_ => {
321-
return Err(Error::new(
322-
ErrorKind::Other,
321+
return Err(Error::other(
323322
"try_timeout_schedule should never execute to here",
324323
));
325324
}

core/tests/coroutine.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ fn coroutine_panic() -> std::io::Result<()> {
2323
})?;
2424
match coroutine.resume()? {
2525
CoroutineState::Error(_) => Ok(()),
26-
_ => Err(std::io::Error::new(
27-
std::io::ErrorKind::Other,
28-
"The coroutine should panic",
29-
)),
26+
_ => Err(std::io::Error::other("The coroutine should panic")),
3027
}
3128
}
3229

@@ -233,8 +230,7 @@ fn coroutine_preemptive() -> std::io::Result<()> {
233230
)
234231
.unwrap();
235232
if result.1.timed_out() {
236-
Err(std::io::Error::new(
237-
std::io::ErrorKind::Other,
233+
Err(std::io::Error::other(
238234
"The monitor should send signals to coroutines in running state",
239235
))
240236
} else {
@@ -279,8 +275,7 @@ fn coroutine_syscall_not_preemptive() -> std::io::Result<()> {
279275
if result.1.timed_out() {
280276
Ok(())
281277
} else {
282-
Err(std::io::Error::new(
283-
std::io::ErrorKind::Other,
278+
Err(std::io::Error::other(
284279
"The monitor should not send signals to coroutines in syscall state",
285280
))
286281
}

hook/src/syscall/windows.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::ffi::{c_int, c_longlong, c_uint, c_void};
2-
use std::io::{Error, ErrorKind};
2+
use std::io::Error;
33
use windows_sys::core::{PCSTR, PCWSTR, PSTR};
44
use windows_sys::Win32::Foundation::{BOOL, HANDLE, TRUE};
55
use windows_sys::Win32::Networking::WinSock::{
@@ -89,6 +89,5 @@ unsafe fn attach() -> std::io::Result<()> {
8989
// impl_hook!("api-ms-win-core-synch-l1-2-0.dll", WAITONADDRESS, WaitOnAddress(address: *const c_void, compareaddress: *const c_void, addresssize: usize, dwmilliseconds: c_uint) -> BOOL);
9090

9191
// Enable the hook
92-
minhook::MinHook::enable_all_hooks()
93-
.map_err(|_| Error::new(ErrorKind::Other, "init all hooks failed !"))
92+
minhook::MinHook::enable_all_hooks().map_err(|_| Error::other("init all hooks failed !"))
9493
}

open-coroutine/examples/file_co.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,5 @@ pub fn main() -> Result<()> {
4242
if let Some(r) = join_handle.timeout_join(Duration::from_secs(30))? {
4343
return r;
4444
}
45-
Err(Error::new(
46-
std::io::ErrorKind::Other,
47-
"Failed to join the task",
48-
))
45+
Err(Error::other("Failed to join the task"))
4946
}

open-coroutine/examples/preemptive.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ pub fn main() -> std::io::Result<()> {
7474
)
7575
.unwrap();
7676
if result.1.timed_out() {
77-
Err(std::io::Error::new(
78-
std::io::ErrorKind::Other,
77+
Err(std::io::Error::other(
7978
"preemptive schedule failed",
8079
))
8180
} else {

0 commit comments

Comments
 (0)