summaryrefslogtreecommitdiffstats
path: root/tokio-current-thread
diff options
context:
space:
mode:
authorMichal 'vorner' Vaner <vorner+github@vorner.cz>2018-07-24 22:27:57 +0200
committerCarl Lerche <me@carllerche.com>2018-07-24 13:27:57 -0700
commit84db3256284e2cd9db18864666fd76e490f944ac (patch)
treef52be212875430770837d5f595c4ac7250254f24 /tokio-current-thread
parent365efec24a5755817810782304be6ed7ede23bb6 (diff)
RunError and few more error types implements Error (#501)
This allows them to be used with things like `failure`.
Diffstat (limited to 'tokio-current-thread')
-rw-r--r--tokio-current-thread/src/lib.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/tokio-current-thread/src/lib.rs b/tokio-current-thread/src/lib.rs
index 758878d5..036893b5 100644
--- a/tokio-current-thread/src/lib.rs
+++ b/tokio-current-thread/src/lib.rs
@@ -40,6 +40,7 @@ use futures::future::{Executor, ExecuteError, ExecuteErrorKind};
use std::fmt;
use std::cell::Cell;
+use std::error::Error;
use std::rc::Rc;
use std::time::{Duration, Instant};
use std::sync::mpsc;
@@ -103,24 +104,76 @@ pub struct RunError {
_p: (),
}
+impl fmt::Display for RunError {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ write!(fmt, "{}", self.description())
+ }
+}
+
+impl Error for RunError {
+ fn description(&self) -> &str {
+ "Run error"
+ }
+}
+
/// Error returned by the `run_timeout` function.
#[derive(Debug)]
pub struct RunTimeoutError {
timeout: bool,
}
+impl fmt::Display for RunTimeoutError {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ write!(fmt, "{}", self.description())
+ }
+}
+
+impl Error for RunTimeoutError {
+ fn description(&self) -> &str {
+ if self.timeout {
+ "Run timeout error (timeout)"
+ } else {
+ "Run timeout error (not timeout)"
+ }
+ }
+}
+
/// Error returned by the `turn` function.
#[derive(Debug)]
pub struct TurnError {
_p: (),
}
+impl fmt::Display for TurnError {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ write!(fmt, "{}", self.description())
+ }
+}
+
+impl Error for TurnError {
+ fn description(&self) -> &str {
+ "Turn error"
+ }
+}
+
/// Error returned by the `block_on` function.
#[derive(Debug)]
pub struct BlockError<T> {
inner: Option<T>,
}
+impl<T> fmt::Display for BlockError<T> {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ write!(fmt, "Block error")
+ }
+}
+
+impl<T: fmt::Debug> Error for BlockError<T> {
+ fn description(&self) -> &str {
+ "Block error"
+ }
+}
+
/// This is mostly split out to make the borrow checker happy.
struct Borrow<'a, U: 'a> {
scheduler: &'a mut Scheduler<U>,