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
#[derive(Debug)]
pub enum BgpError {
Static(&'static str),
InsufficientBufferSize,
ProtocolError,
TooManyData,
DynStr(std::string::String),
Other(Box<dyn std::error::Error + Send + Sync>),
}
impl BgpError {
#[inline]
pub fn static_str(ms: &'static str) -> BgpError {
BgpError::Static(ms)
}
#[inline]
pub fn from_string(s: std::string::String) -> BgpError {
BgpError::DynStr(s)
}
#[inline]
pub fn from_error(e: Box<dyn std::error::Error + Send + Sync>) -> BgpError {
BgpError::Other(e)
}
#[inline]
pub fn insufficient_buffer_size() -> BgpError {
BgpError::InsufficientBufferSize
}
#[inline]
pub fn protocol_error() -> BgpError {
BgpError::ProtocolError
}
#[inline]
pub fn too_many_data() -> BgpError {
BgpError::TooManyData
}
}
impl std::fmt::Display for BgpError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
BgpError::InsufficientBufferSize => write!(f, "BgpError InsufficientBufferSize"),
BgpError::ProtocolError => write!(f, "BgpError ProtocolError"),
BgpError::TooManyData => write!(f, "BgpError TooManyData"),
BgpError::Static(s) => write!(f, "BgpError {}", s),
BgpError::DynStr(s) => write!(f, "BgpError {}", s),
BgpError::Other(e) => write!(f, "BgpError {}", e),
}
}
}
impl std::error::Error for BgpError {}
impl From<std::io::Error> for BgpError {
#[inline]
fn from(error: std::io::Error) -> Self {
BgpError::Other(Box::new(error))
}
}
impl From<std::net::AddrParseError> for BgpError {
#[inline]
fn from(error: std::net::AddrParseError) -> Self {
BgpError::Other(Box::new(error))
}
}