stun_client/
error.rs

1use thiserror::Error;
2
3/// Defines the error used by the stun_client library.
4#[derive(Error, Debug)]
5pub enum STUNClientError {
6    #[error("cannot parse as STUN message")]
7    ParseError(),
8    #[error(transparent)]
9    IOError(#[from] std::io::Error),
10    #[error("not supported by the server: {0}")]
11    NotSupportedError(String),
12    #[error("request timeout")]
13    TimeoutError(),
14    #[error("unknown error: {0}")]
15    Unknown(String),
16}
17
18impl Clone for STUNClientError {
19    fn clone(&self) -> Self {
20        match self {
21            Self::ParseError() => Self::ParseError(),
22            Self::IOError(e) => Self::IOError(std::io::Error::new(e.kind(), e.to_string())),
23            Self::NotSupportedError(msg) => Self::NotSupportedError(msg.clone()),
24            Self::TimeoutError() => Self::TimeoutError(),
25            Self::Unknown(msg) => Self::Unknown(msg.clone()),
26        }
27    }
28}