Simplify with unwrap_or_else().

This commit is contained in:
Jakob Stoklund Olesen
2016-09-17 12:36:35 -07:00
parent a4774ce87d
commit 23887358dd

View File

@@ -127,20 +127,17 @@ fn worker_thread(thread_num: usize,
}) })
.unwrap(); .unwrap();
let result = match catch_unwind(|| runone::run(path.as_path())) { let result = catch_unwind(|| runone::run(path.as_path())).unwrap_or_else(|e| {
Ok(r) => r, // The test panicked, leaving us a `Box<Any>`.
Err(e) => { // Panics are usually strings.
// The test panicked, leaving us a `Box<Any>`. if let Some(msg) = e.downcast_ref::<String>() {
// Panics are usually strings. Err(format!("panicked in worker #{}: {}", thread_num, msg))
if let Some(msg) = e.downcast_ref::<String>() { } else if let Some(msg) = e.downcast_ref::<&'static str>() {
Err(format!("panicked in worker #{}: {}", thread_num, msg)) Err(format!("panicked in worker #{}: {}", thread_num, msg))
} else if let Some(msg) = e.downcast_ref::<&'static str>() { } else {
Err(format!("panicked in worker #{}: {}", thread_num, msg)) Err(format!("panicked in worker #{}", thread_num))
} else {
Err(format!("panicked in worker #{}", thread_num))
}
} }
}; });
replies.send(Reply::Done { replies.send(Reply::Done {
jobid: jobid, jobid: jobid,