broker_tokio/task/
error.rs1use std::any::Any;
2use std::fmt;
3use std::io;
4use std::sync::Mutex;
5
6doc_rt_core! {
7 pub struct JoinError {
9 repr: Repr,
10 }
11}
12
13enum Repr {
14 Cancelled,
15 Panic(Mutex<Box<dyn Any + Send + 'static>>),
16}
17
18impl JoinError {
19 #[doc(hidden)]
20 #[deprecated]
21 pub fn cancelled() -> JoinError {
22 Self::cancelled2()
23 }
24
25 pub(crate) fn cancelled2() -> JoinError {
26 JoinError {
27 repr: Repr::Cancelled,
28 }
29 }
30
31 #[doc(hidden)]
32 #[deprecated]
33 pub fn panic(err: Box<dyn Any + Send + 'static>) -> JoinError {
34 Self::panic2(err)
35 }
36
37 pub(crate) fn panic2(err: Box<dyn Any + Send + 'static>) -> JoinError {
38 JoinError {
39 repr: Repr::Panic(Mutex::new(err)),
40 }
41 }
42}
43
44impl fmt::Display for JoinError {
45 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
46 match &self.repr {
47 Repr::Cancelled => write!(fmt, "cancelled"),
48 Repr::Panic(_) => write!(fmt, "panic"),
49 }
50 }
51}
52
53impl fmt::Debug for JoinError {
54 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
55 match &self.repr {
56 Repr::Cancelled => write!(fmt, "JoinError::Cancelled"),
57 Repr::Panic(_) => write!(fmt, "JoinError::Panic(...)"),
58 }
59 }
60}
61
62impl std::error::Error for JoinError {}
63
64impl From<JoinError> for io::Error {
65 fn from(src: JoinError) -> io::Error {
66 io::Error::new(
67 io::ErrorKind::Other,
68 match src.repr {
69 Repr::Cancelled => "task was cancelled",
70 Repr::Panic(_) => "task panicked",
71 },
72 )
73 }
74}