summaryrefslogtreecommitdiffstats
path: root/tokio/src/executor/task/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio/src/executor/task/error.rs')
-rw-r--r--tokio/src/executor/task/error.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/tokio/src/executor/task/error.rs b/tokio/src/executor/task/error.rs
new file mode 100644
index 00000000..17d3911c
--- /dev/null
+++ b/tokio/src/executor/task/error.rs
@@ -0,0 +1,48 @@
+use std::any::Any;
+use std::fmt;
+
+/// Task failed to execute to completion.
+pub struct Error {
+ repr: Repr,
+}
+
+enum Repr {
+ Cancelled,
+ Panic(Box<dyn Any + Send + 'static>),
+}
+
+impl Error {
+ /// Create a new `cancelled` error
+ pub fn cancelled() -> Error {
+ Error {
+ repr: Repr::Cancelled,
+ }
+ }
+
+ /// Create a new `panic` error
+ pub fn panic(err: Box<dyn Any + Send + 'static>) -> Error {
+ Error {
+ repr: Repr::Panic(err),
+ }
+ }
+}
+
+impl fmt::Display for Error {
+ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match &self.repr {
+ Repr::Cancelled => write!(fmt, "cancelled"),
+ Repr::Panic(_) => write!(fmt, "panic"),
+ }
+ }
+}
+
+impl fmt::Debug for Error {
+ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match &self.repr {
+ Repr::Cancelled => write!(fmt, "task::Error::Cancelled"),
+ Repr::Panic(_) => write!(fmt, "task::Error::Panic(...)"),
+ }
+ }
+}
+
+impl std::error::Error for Error {}