1use crate::AlertDescription;
2
3#[derive(Debug)]
4pub enum ServerError {
5 SendAlert(AlertDescription),
6 RecvAlert(AlertDescription),
7 Io(std::io::Error),
8}
9
10impl From<std::io::Error> for ServerError {
11 fn from(value: std::io::Error) -> Self {
12 Self::Io(value)
13 }
14}
15
16impl From<AlertDescription> for ServerError {
17 fn from(value: AlertDescription) -> Self {
18 Self::SendAlert(value)
19 }
20}
21
22impl std::fmt::Display for ServerError {
23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 match self {
25 ServerError::SendAlert(alert_description) => {
26 write!(f, "Sent alert {alert_description:?}")
27 }
28 ServerError::RecvAlert(alert_description) => {
29 write!(f, "Received alert {alert_description:?}")
30 }
31 ServerError::Io(error) => error.fmt(f),
32 }
33 }
34}
35
36impl std::error::Error for ServerError {}