1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
use crate::{ import::* };
#[ derive( Debug ) ]
pub struct Error
{
kind: ErrorKind,
}
impl StdError for Error {}
#[ derive( Copy, Clone, PartialEq, Eq, Debug ) ]
pub enum ErrorKind
{
DoubleExecutorInit,
Spawn,
Run,
SpawnLocalOnThreadPool,
WrongExecutor,
NoExecutorInitialized,
__Nonexhaustive,
}
impl fmt::Display for ErrorKind
{
fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result
{
match self
{
Self::DoubleExecutorInit => fmt::Display::fmt( "DoubleExecutorInit: Cannot initialize global executor twice.", f ) ,
Self::Spawn => fmt::Display::fmt( "Spawn: Failed to spawn a future.", f ) ,
Self::Run => fmt::Display::fmt( "Run: Failed to run an executor to completion.", f ) ,
Self::SpawnLocalOnThreadPool => fmt::Display::fmt( "Spawn: You can not spawn `!Send` futures on a thread pool. If your feature is `Send`, use `rt::spawn`, otherwise initialize this thread with a Local executor.", f ) ,
Self::WrongExecutor => fmt::Display::fmt( "You tried to use a functionality specific to a certain executor while another executor was being used for this thread.", f ) ,
Self::NoExecutorInitialized => fmt::Display::fmt( "You must initialize an executor on this thread before calls to spawn.", f ) ,
_ => unreachable!(),
}
}
}
impl fmt::Display for Error
{
fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result
{
write!( f, "async_runtime::Error: {}", &self.kind )
}
}
impl Error
{
pub fn new( kind: ErrorKind ) -> Self
{
Error { kind }
}
pub fn kind( &self ) -> &ErrorKind
{
&self.kind
}
}
impl From<ErrorKind> for Error
{
fn from( kind: ErrorKind ) -> Error
{
Error { kind }
}
}