Skip to content

Commit ff572d3

Browse files
committed
fix clippy
1 parent f167a66 commit ff572d3

File tree

6 files changed

+53
-82
lines changed

6 files changed

+53
-82
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/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
}

open-coroutine/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ pub fn crate_task<P: 'static, R: 'static, F: FnOnce(P) -> R>(
133133
let result: &'static mut std::io::Result<R> = Box::leak(Box::new(
134134
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| (data.0)(data.1)))
135135
.map_err(|e| {
136-
Error::new(
137-
ErrorKind::Other,
136+
Error::other(
138137
e.downcast_ref::<&'static str>()
139138
.map_or("task failed without message", |msg| *msg),
140139
)
@@ -165,7 +164,7 @@ impl<R> JoinHandle<R> {
165164
unsafe {
166165
let ptr = task_timeout_join(self, dur.as_nanos().try_into().expect("overflow"));
167166
match ptr.cmp(&0) {
168-
Ordering::Less => Err(Error::new(ErrorKind::Other, "timeout join failed")),
167+
Ordering::Less => Err(Error::other("timeout join failed")),
169168
Ordering::Equal => Ok(None),
170169
Ordering::Greater => Ok(Some((*Box::from_raw(ptr as *mut std::io::Result<R>))?)),
171170
}
@@ -176,7 +175,7 @@ impl<R> JoinHandle<R> {
176175
unsafe {
177176
let ptr = task_join(&self);
178177
match ptr.cmp(&0) {
179-
Ordering::Less => Err(Error::new(ErrorKind::Other, "join failed")),
178+
Ordering::Less => Err(Error::other("join failed")),
180179
Ordering::Equal => Ok(None),
181180
Ordering::Greater => Ok(Some((*Box::from_raw(ptr as *mut std::io::Result<R>))?)),
182181
}
@@ -192,7 +191,7 @@ impl<R> JoinHandle<R> {
192191
for handle in slice {
193192
let left_time = timeout_time.saturating_sub(open_coroutine_core::common::now());
194193
if 0 == left_time {
195-
return Err(Error::new(ErrorKind::Other, "timeout join failed"));
194+
return Err(Error::other("timeout join failed"));
196195
}
197196
if let Ok(x) = handle.timeout_join(Duration::from_nanos(left_time).min(SLICE)) {
198197
return Ok(x);

0 commit comments

Comments
 (0)