Skip to main content

ling_net/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub enum NetError {
5    Io(std::io::Error),
6    Connect(String),
7    Timeout,
8    Protocol(String),
9    Tls(String),
10    Http(String),
11    Unsupported(String),
12}
13
14impl fmt::Display for NetError {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            Self::Io(e)             => write!(f, "io: {e}"),
18            Self::Connect(msg)      => write!(f, "connect: {msg}"),
19            Self::Timeout           => write!(f, "connection timed out"),
20            Self::Protocol(msg)     => write!(f, "protocol error: {msg}"),
21            Self::Tls(msg)          => write!(f, "tls error: {msg}"),
22            Self::Http(msg)         => write!(f, "http error: {msg}"),
23            Self::Unsupported(msg)  => write!(f, "unsupported: {msg}"),
24        }
25    }
26}
27
28impl std::error::Error for NetError {}
29impl From<std::io::Error> for NetError {
30    fn from(e: std::io::Error) -> Self { Self::Io(e) }
31}