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
use crate::frame::FrameDecodeError;
use thiserror::Error;
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum ConnectionError {
#[error("i/o error: {0}")]
Io(#[from] std::io::Error),
#[error("decode error: {0}")]
Decode(#[from] FrameDecodeError),
#[error("number of stream ids has been exhausted")]
NoMoreStreamIds,
#[error("connection is closed")]
Closed,
#[error("maximum number of streams reached")]
TooManyStreams
}
impl ConnectionError {
pub(crate) fn io_kind(&self) -> Option<std::io::ErrorKind> {
match self {
ConnectionError::Io(e) => Some(e.kind()),
ConnectionError::Decode(FrameDecodeError::Io(e)) => Some(e.kind()),
_ => None
}
}
}
impl From<futures::channel::mpsc::SendError> for ConnectionError {
fn from(_: futures::channel::mpsc::SendError) -> Self {
ConnectionError::Closed
}
}
impl From<futures::channel::oneshot::Canceled> for ConnectionError {
fn from(_: futures::channel::oneshot::Canceled) -> Self {
ConnectionError::Closed
}
}